用while循环输出1-1000之间的水仙花数

水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)

第1个回答  2010-11-17
#include <stdio.h>

int main()
{
int x,sum,count;

for(x=101;x<=999;++x)
{
count=x;sum=0;
while(count!=0)
{
sum+=(count%10)*(count%10)*(count%10);
count/=10;
}

if(sum==x)
printf("水仙花数:%d\n",x);

}
return 0;
}本回答被提问者采纳
相似回答