//程序的功能:算出满足条件的所有水仙花数 法一:
# include <stdio.h>
main()
{
int x,a,b,c;
printf("\n 输出的水仙花数为:");
for(x=100;x<1000;x++)
{
a=x/100;
b=(x-a*100)/10;
c=x-a*100-b*10;
if(x==a*a*a+b*b*b+c*c*c) printf("%5d\n",x);
}
}
法二:
# include <stdio.h>
main()
{
int x,a,b,c;
printf("\n 输出水仙花的数为:"); for(x=100;x<1000;x++)
for(a=1;a<=9;a++)
for(b=0;b<=9;b++)
for(c=0;c<=9;c++)
{
x=a*100+b*10+c;
if(x==a*a*a+b*b*b+c*c*c) printf("\n %d\n",x); }
}
//程序的功能:算出满足条件的所有水仙花数 法一:
# include <stdio.h>
main()
{
int x,a,b,c;
printf("\n 输出的水仙花数为:");
for(x=100;x<1000;x++)
{
a=x/100;
b=(x-a*100)/10;
c=x-a*100-b*10;
if(x==a*a*a+b*b*b+c*c*c) printf("%5d\n",x);
}
}
法二:
# include <stdio.h>
main()
{
int x,a,b,c;
printf("\n 输出水仙花的数为:"); for(x=100;x<1000;x++)
for(a=1;a<=9;a++)
for(b=0;b<=9;b++)
for(c=0;c<=9;c++)
{
x=a*100+b*10+c;
if(x==a*a*a+b*b*b+c*c*c) printf("\n %d\n",x); }
}