11智能在线
新记
用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;
}本回答被提问者采纳
相似回答
大家正在搜
相关问题
用while语句写水仙花数(100-999) 你为什么会输出...
怎样加入for循环,使得输出数1000内所有的水仙花数
分别使用while、do-while和for语句编程,找出所...
javascript 输出100~1000出所有水仙花数,用...
要输出1到10000之间的所有水仙花数,帮我看看这程序错哪了
Java用while语句来找出所有的水仙花数
用for循环求出100-1000的水仙花数
求大神。我在算1-1000的水仙花数 c语言