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 are the types of i/o functions?
Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.
C program to find all possible outcomes of a dice?
What are the features of the c language?
What is pointers in c?
Process by which one bit pattern in to another by bit wise operation is?
Linked lists -- can you tell me how to check whether a linked list is circular?
What is "Hungarian Notation"?
Explain the bubble sort algorithm.
Can a pointer point to null?
Can you assign a different address to an array tag?
What is property type c?
What are pointers? Why are they used?
How many levels of indirection in pointers can you have in a single declaration?
Explain how can I remove the trailing spaces from a string?