In the first case, I suspect that the compiler optimized the value 10*10 without actually calling pow (compilers really do this). In the second case, it looks like you have a floating point rounding error. The result is almost 100, but not quite, and an implicit cast to int truncates it.
The pow function works on double , not int .
In the general case (but not always), when you convert double numbers to integers, you call round() . For example:
int i = (int) round(pow(10,j));
If your C library does not have this, you can emulate:
#define round(x) floor((x)+0.5)
paddy 01 Oct '13 at 22:19 2013-10-01 22:19
source share