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



write a program to find a given no. is divisible by 3 or not without using any arthimetic operators..

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

write a program to find a given no. is divisible by 3 or not without using any arthimetic operators..

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

write a program to find a given no. is divisible by 3 or not without using any arthimetic operators..

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

Post New Answer

More C Interview Questions

Program to simulate second clock

2 Answers  


What does node * mean?

0 Answers  


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?

0 Answers  


20. main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); } Answer:??????

2 Answers  


what are bit fields in c?

2 Answers  


What is call by reference in functions?

1 Answers  


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

0 Answers  


difference between semaphores and mutex?

1 Answers  


how can write all 1to 100 prime numbers using for loop,if and break ?

2 Answers   TCS,


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 ...

1 Answers   Philips,


Write a program to find given number is even or odd without using any control statement.

2 Answers  


There seem to be a few missing operators ..

0 Answers  


Categories