write a program to find a given no. is divisible by 3 or not
without using any arthimetic operators?
Answer Posted / sanjay bhosale
#include<stdio.h>
int main()
{
int x=0,y=-3;
printf("\n Enter the number :\t");
scanf("%d",&x);
int xor, and, temp,tempvar=x;
x = (x>0) ? x:(-x);
while(x>0)
{
and = x & y;
xor = x ^ y;
while(and != 0 )
{
and <<= 1;
temp = xor ^ and;
and &= xor;
xor = temp;
}
x = xor;
}
if(x==0)
printf("%d is divisible by 3",tempvar);
else
printf(" %d is not divisible by 3",tempvar);
return 0;
}
| Is This Answer Correct ? | 11 Yes | 1 No |
Post New Answer View All Answers
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
Explain how can a program be made to print the line number where an error occurs?
What is the difference between c &c++?
using for loop sum 2 number of any 4 digit number in c language
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
What is variables in c?
What is sizeof c?
What is the usage of the pointer in c?
What is array of structure in c programming?
Is c is a low level language?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
When can you use a pointer with a function?
How would you obtain the current time and difference between two times?