Your variables t1 , t2 and t3 must be of type double , because pow() returns double.
But if you want them to be of type int , use the round() function.
int t1 = pow(10,2); int t2 = round(pow(n,2)); int t3 = 2 * round(pow(n,2));
It rounds the returned values 99.9... and 199.9... to 100.0 and 200.0 . And then t2 == 100 , because it is of type int , as well as t3 .
The output will be:
100 100 200
Since the round function returns an integer value, the one closest to x rounds half the cases from zero, regardless of the current rounding direction.
UPDATE: Here is a comment from math.h :
/* Excess precision when using a 64-bit mantissa for FPU math ops can cause unexpected results with some of the MSVCRT math functions. For example, unless the function return value is stored (truncating to 53-bit mantissa), calls to pow with both x and y as integral values sometimes produce a non-integral result. ... */
source share