A simple calculation: 3^20%15.
The answer, according to a calculator, is 6.
The following code generates answer 7.
#include <stdio.h>
#include <math.h>
int main() {
int i = 20;
printf("%d\n", ((int)pow(3,20)%15));
return 0;
}
If I replace 20
in the printf
statement with the variable i
, it gives -8
as output.
Assuming that the calculator is corrent (or not?), what is the problem in the program?
Thank you.