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

what is reason of your company position's in india no. 1.

0 Answers   Accenture, TCS,


what is a function pointer and how all to declare ,define and implement it ???

4 Answers   Honeywell,


What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?

1 Answers  


What does static variable mean in c?

0 Answers  


how can i get the string which is having two spaces at the end.suppose the string is "Hello World ".Now at the end i have two spaces.i need to print with that spaces .

1 Answers  






What is time complexity c?

0 Answers  


Given an array of numbers, except for one number all the others occur twice. Give an algorithm to find that number which occurs only once in the array.

6 Answers  


What is use of bit field?

0 Answers  


What is the use of c language in real life?

0 Answers  


What is the output for the following program #include<stdio.h> main() { char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0])); printf("%d\n",flag); }

5 Answers   ADITI, Wipro,


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

0 Answers  


What is bin sh c?

0 Answers  


Categories