Nicomachus定理的验证

来源:百度知道 编辑:UC知道 时间:2024/05/31 08:39:23
需要一个验证Nicomachus定理的C语言程序,希望高手能够提供一下!谢谢!
输入一个整数,然后对这个整数进行验证

之前有网友问过,搜索一下就可以找到了!!

//---------------------------------------------------------------------------

#include <stdio.h>

int lf(const int a,int n)
{
int i=n,s=0;
while (s<a)
{
s+=n;
n+=2;
}

if (s==a){
while (s)
{
printf("%d\t",i);
s-=i;
i+=2;
}
return 1;
}
return 0;
}
int main(void)
{
int i,a;
scanf("%d",&a);
a=a*a*a;
for (i=1; i<a; i+=2) {
if (lf(a,i)) break;
}
return 0;
}
//---------------------------------------------------------------------------