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


Please Help Members By Posting Answers For Below Questions

Explain what is meant by high-order and low-order bytes?

631


how can f be used for both float and double arguments in printf? Are not they different types?

606


Define VARIABLE?

686


write a program in c language to print your bio-data on the screen by using functions.

6243


Describe how arrays can be passed to a user defined function

776






which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;

2391


What is the correct code to have following output in c using nested for loop?

609


Is the exit() function same as the return statement? Explain.

656


What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

620


What type is sizeof?

580


What is the difference between c and python?

579


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

1594


How reliable are floating-point comparisons?

621


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.

2215


What is volatile variable how do you declare it?

562