write a program to find a given no. is divisible by 3 or not
without using any arthimetic operators?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / siva prabhu
#include<stdio.h>
int main()
{
int x,y,i=0,j=0,r=0;
printf("enter a num\n");
scanf("%d",&x);
if(x>3)
{
while(x>0)
{
i=0;
while(i<3)
{
--x;
++i;
}
++j;
if(x<3)
{
r=x;
printf("reminder is %d\n",x);
break;
}
}
if(r==0)
printf("the given is divisible by 3\n");
else
printf("the given no. is not %% by %3\n");
}
else
{
printf("the given no. is not %% by %3\n");
}
return 0;
}
Is This Answer Correct ? | 10 Yes | 3 No |
Answer / viral
#include<conio.h>
#include<stdio.h>
void main()
{
int a;
clrscr();
printf("enter the number ");
scanf("%d",&a);
if(a%3==0)
printf("the number %d is divisble by 3",a);
else
printf("the number %d is not divisible by 3",a);
getch();
}
Is This Answer Correct ? | 20 Yes | 48 No |
Program to simulate second clock
What does node * mean?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
20. main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); } Answer:??????
what are bit fields in c?
What is call by reference in functions?
the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset
difference between semaphores and mutex?
how can write all 1to 100 prime numbers using for loop,if and break ?
write a c code "if you give a any decimal number then print that number in english alphabet"? ex: i/p: 552 o/p: five hundred fifty two ...
Write a program to find given number is even or odd without using any control statement.
There seem to be a few missing operators ..