您的 variables t1,t2并且t3必须是类型double,因为pow()返回双精度。
但是,如果您确实希望它们是 typeint,请使用round()function。
int t1 = pow(10,2);
int t2 = round(pow(n,2));
int t3 = 2 * round(pow(n,2));
它将返回的值四舍五入到99.9...和。然后因为它是类型的,所以也是。199.9...100.0200.0t2 == 100intt3
输出将是:
100
100
200
因为round无论当前的舍入方向如何,该函数返回最接近 x 舍入的整数值中途情况远离零。
更新:这是来自的评论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. ... */