printf("enter an integer\n");
scanf("%d",&x);
y=x%pow(10,3);
printf("the result is %d",y);
return 0;}
The compiler tell me there is something wrong with the "pow",but I
don't know what's the wrong?
> # include <stdio.h>
> # include <math.h>
> int main()
> { long int x,y;
>
> printf("enter an integer\n");
> scanf("%d",&x);
>
> y=x%pow(10,3);
[snip]
> The compiler tell me there is something wrong with the "pow",but I
> don't know what's the wrong?
pow() returns a floating point (in this case, I guess a double) and x is a
long int. That is not a valid pair of operand types for the % operator.
Best
Kai-Uwe Bux
my compiler says:
testmod.cpp:8: warning: format ‘%d’ expects type ‘int*’, but argument 2
has type ‘long int*’
testmod.cpp:10: error: invalid operands of types ‘long int’ and ‘double’
to binary ‘operator%’
testmod.cpp:12: warning: format ‘%d’ expects type ‘int’, but argument 2
has type ‘long int’
It looks pretty much clear. Listen to your compiler. It's your friend.
Best wishes,
Zeppe
What's wrong with 1000?
Nit: 1000 does not occur in the above whereas 1000.0 does occur.
Best
Kai-Uwe Bux
But 1000 would work, whereas 1000.0 wouldn't.
Ah, now I understand your point: you meant to replace pow(10,3) by 1000.
Sorry for the noise.
Kai-Uwe Bux
thanks
thanks
thanks