69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c;
int s;
int n;
for (a = 1; a < 10; a++)
{
for (b = 0; b < 10; b++)
{
for (c = 0; c < 10; c++)
{
s = a * 100 + b * 10 + c;
n=a*a+b*b+c*c;
if(n==s)
printf("%d ", n);
}
}
}
}
#include <stdio.h>
int main(void)
{
int a, b, c;
int s;
int n;
for (a = 1; a < 10; a++)
{
for (b = 0; b < 10; b++)
{
for (c = 0; c < 10; c++)
{
s = a*100 + b*10 + c;
n = a*a*a + b*b*b + c*c*c;
if(n==s)
printf("%4d\n", n);
}
}
}
return 0;
}
lz,其实这个问题可以搜到的,另外lz注意,这里应该用不到#include <stdlib.h>
吧,代码最后最好加一个return 0; ,毕竟前面是int main(),还有就是可以把最后的%d变成%4d,这也比%d ;稍微好看一些吧(个人意见)