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
Define macros.
Explain what are run-time errors?
a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none
How can you pass an array to a function by value?
What is union and structure?
Do pointers store the address of value or the actual value of a variable?
What is gets() function?
What is hashing in c?
What is a memory leak? How to avoid it?
Explain pointer. What are function pointers in C?
What is the advantage of using #define to declare a constant?
Explain how do you override a defined macro?
What is a dynamic array in c?
Is c pass by value or reference?
Why c language?