尼科彻斯定理,我只有输入4才有结果,为什么我输入其他数字就没结果了
#include <stdio.h>#include <math.h>
int main()
{
int i, j, sum = 0;
int n, cubed;
printf("请输入一个整数:");
scanf("%d", &i);
cubed = pow(i, 3);
for(j = 1; j < cubed; j += 2)
{
for(n = 1; n < cubed; n += 2)
{
sum += n;
if(sum == cubed)
{
if(n - j > 4)
{
printf("%d = %d + %d + ... + %d", cubed, j, j+2, n);
}
else
{
printf("%d = %d + %d + %d", cubed, j, j+2, j+4);
}
goto A;
}
if(sum > cubed)
{
sum = 0;
break;
}
}
}
A:
return 0;
} for(n = j; n < cubed; n += 2)
页:
[1]