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

regarding pointers concept

0 Answers  


What is the use of void pointer and null pointer in c language?

0 Answers  


who did come first hen or agg

15 Answers   Infosys,


Is there a built-in function in C that can be used for sorting data?

0 Answers  


What is f'n in math?

0 Answers  






what is diognisis?

1 Answers  


hi any body pls give me company name interview conduct "c" language only

0 Answers  


What compilation do?

7 Answers   Geometric Software, Infosys,


Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.

0 Answers  


What is difference between far and near pointers?

0 Answers  


What are run-time errors?

0 Answers  


write a program that will read the temperature in Celsius and convert that into Fahrenheit.

1 Answers  


Categories