Im trying to execute the below program,but im getting error...
can anyone help me to solve this problem...
#include<stdio.h>
int main()
{
double x;
scanf("%lf",&x);
if((x % 100) == 0)
printf("%lf is divisible by 100",x);
else
printf("%lf is not divisible by 100",x);
return 0;
}
#include<stdio.h>
int main()
{
int x = 0;
scanf("%d",&x);
if((x % 100) == 0)
printf("%lf is divisible by 100",x);
else
printf("%lf is not divisible by 100",x);
return 0;
}
You cannot use the '%' operator on double and float.
You may want cast it to an int, or to a long, like this:
1 2 3 4 5 6 7 8 9 10
int main()
{
double x = 0;
scanf("%lf",&x);
if ( (((long)x) % 100) == 0)
printf("%lf is divisible by 100",x);
else
printf("%lf is not divisible by 100",x);
return 0;
}
Why not multiply by 10 (or however many decimal places you have times 100, 1000, etc, depending on how many decimal points there are) and then divide by 100. If the answer is even, then it divides evenly.