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 |
regarding pointers concept
What is the use of void pointer and null pointer in c language?
who did come first hen or agg
Is there a built-in function in C that can be used for sorting data?
What is f'n in math?
what is diognisis?
hi any body pls give me company name interview conduct "c" language only
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.
What is difference between far and near pointers?
What are run-time errors?
write a program that will read the temperature in Celsius and convert that into Fahrenheit.