问题遇到的现象和发生背景
水仙花数问题
用代码块功能插入代码,请勿粘贴截图
#include<stdio.h>
#include<math.h>
int main()
{
int n,x;
scanf("%d",&n);
int i;
for(i=pow(10,n-1);i<pow(10,n);i++)
{
int a[8]={0};
int b;
b=i;
// while(b>0)
// {
// x=0;
// a[x]=b%10;
// b/=10;
// x++;
// }
for(x=0;b>0;x++){
a[x]=b%10;
b/=10;
}
if(i==pow(a[0],3)+ ..正文不能重复,就是所有数组的三次方相加。
{
printf("%d\n",i);
}
}
return 0;
}
运行结果及报错内容
为什么用while循环不行,而用for循环就可以?并且我发现只能输出三位数,三位以上的就不行了。
我的解答思路和尝试过的方法
想了半天都不会
我想要达到的结果
救助!