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
Explain what is meant by high-order and low-order bytes?
how can f be used for both float and double arguments in printf? Are not they different types?
Define VARIABLE?
write a program in c language to print your bio-data on the screen by using functions.
Describe how arrays can be passed to a user defined function
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
What is the correct code to have following output in c using nested for loop?
Is the exit() function same as the return statement? Explain.
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
What type is sizeof?
What is the difference between c and python?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
How reliable are floating-point comparisons?
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
What is volatile variable how do you declare it?