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

Define macros.

785


Explain what are run-time errors?

610


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

725


How can you pass an array to a function by value?

602


What is union and structure?

574






Do pointers store the address of value or the actual value of a variable?

610


What is gets() function?

673


What is hashing in c?

644


What is a memory leak? How to avoid it?

577


Explain pointer. What are function pointers in C?

628


What is the advantage of using #define to declare a constant?

621


Explain how do you override a defined macro?

587


What is a dynamic array in c?

597


Is c pass by value or reference?

595


Why c language?

648