|
楼主 |
发表于 2020-2-24 23:43:21
|
显示全部楼层
调试前的关键行代码为: sum = sum + pow(k, 3);
部分执行过程结果如下:
i = 150,j = 150, k = 0, sum = 0
i = 150,j = 15, k = 5, sum = 124-------->有问题
i = 150,j = 1, k = 1, sum = 125
i = 151,j = 151, k = 1, sum = 1
i = 151,j = 15, k = 5, sum = 125
i = 151,j = 1, k = 1, sum = 126
i = 152,j = 152, k = 2, sum = 8
i = 152,j = 15, k = 5, sum = 132------->应该是133,有问题
i = 152,j = 1, k = 1, sum = 133
i = 153,j = 153, k = 3, sum = 27
i = 153,j = 15, k = 5, sum = 151----------->应该为152,有问题
i = 153,j = 1, k = 1, sum = 152
i = 154,j = 154, k = 4, sum = 64
i = 154,j = 15, k = 5, sum = 188
i = 155,j = 155, k = 5, sum = 124
i = 155,j = 15, k = 5, sum = 248
i = 156,j = 156, k = 6, sum = 216
i = 157,j = 157, k = 7, sum = 343
i = 158,j = 158, k = 8, sum = 512
i = 159,j = 159, k = 9, sum = 729
可能是编译器不同导致我们执行结果不同,但是在我的编译器中单独的pow函数测试程序中结果却又是:pow(5,3)== 125:
# include <stdio.h>
# include <math.h>
int main()
{
int i;
i = pow(5,3);
printf("%d", i);
return 0;
}
|
|