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
Is sizeof a keyword in c?
What are directives in c?
What is the difference between arrays and pointers?
Compare array data type to pointer data type
What are the advantages and disadvantages of c language?
How can I manipulate strings of multibyte characters?
the question is that what you have been doing all these periods (one year gap)
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
how to write optimum code to divide a 50 digit number with a 25 digit number??
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
Explain heap and queue.
What is the code for 3 questions and answer check in VisualBasic.Net?
What is null in c?
What is a list in c?
How does sizeof know array size?