读书人

打印凌波仙子数 为什么木有输出

发布时间: 2012-10-19 16:53:35 作者: rapoo

打印水仙花数 为什么木有输出啊
#include<stdio.h>
main()
{
int i,t,n,temp;
t=0;
temp=0;
for(i=100;i<1000;i++)
{
n=i;
while(n!=0)
{
t=n%10;
n=n/10;
temp=temp+t*t*t; //用temp保存
}
if(temp==i)
printf("100~1000水仙花数:%4d\n",i);
}
}
不知道错在哪里了 帮忙看看 谢谢

[解决办法]

C/C++ code
void main(void){       int i, t, n, temp;    //t = 0;    //temp = 0;    for (i=100; i<1000; i++)    {        n = i;        temp = 0;        while (n != 0)        {            t = n % 10;            n = n / 10;            temp = temp + t*t*t; //用temp保存        }        if (temp == i)            printf("100~1000水仙花数:%4d\n", i);    }}
[解决办法]
楼上正解,temp每次循环都需要重新计数的

读书人网 >C语言

热点推荐