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

‎How to define structures? · ‎

0 Answers  


what does " calloc" do?

7 Answers   Cadence, Logos,


What's a good way to check for "close enough" floating-point equality?

0 Answers   Celstream,


code for find determinent of amatrix

0 Answers  


what is use of malloc and calloc?

0 Answers  


Write a program in c using only loops to print * * * * * *******

2 Answers   IBM,


write a program to print largest number of each row of a 2D array

0 Answers  


Where does the name "C" come from, anyway?

0 Answers   Celstream,


What is your favorite subject?

1 Answers   Ericsson, Invendis, Tech Mahindra,


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

0 Answers   Subex,


What is a stream?

0 Answers  


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

1 Answers   CMS,


Categories