#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
int a,b,c,d;
for(x=1;x<1000;x++)
{
a=x/100;
b=x%100/10;
c=x%10;
if(x==a*a*a+b*b*b+c*c*c)
printf("%d\n",x);
}
return 0;
}
心得体会:知道怎么算水仙花数。
本文通过C语言程序展示了如何计算1000以内的所有水仙花数。水仙花数是指一个三位数,其各位数字立方和等于该数本身。程序采用for循环遍历1到999之间的所有整数,并通过模运算和除法计算每一位数字。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x;
int a,b,c,d;
for(x=1;x<1000;x++)
{
a=x/100;
b=x%100/10;
c=x%10;
if(x==a*a*a+b*b*b+c*c*c)
printf("%d\n",x);
}
return 0;
}
心得体会:知道怎么算水仙花数。
236
1480

被折叠的 条评论
为什么被折叠?