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
What does double pointer mean in c?
What is the difference between fread buffer() and fwrite buffer()?
Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions
What is a far pointer in c?
Explain what is the advantage of a random access file?
What is cohesion and coupling in c?
How can I dynamically allocate arrays?
Can you add pointers together? Why would you?
How important is structure in life?
What is a wrapper function in c?
When would you use a pointer to a function?
how to count no of words,characters,lines in a paragraph.
a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);
Why does everyone say not to use gets?