7-2 水仙花数 (20 分)

7-2 水仙花数 (20 分)
这是我写的求法,随着位数的增加运算难度的增加会使8位以上的水仙花数较难输出,看编译器性能啦

7-2 水仙花数 (20 分)
#include #include int main() { int n,a,b,i,m,temp,c,d; scanf("%d",&n);//3<=N<=7代表位数 a=pow(10,n)-1;//位数区域最大值 b=pow(10,(n-1));//位数最初值 for(i=b;i<=a;i++)//限制不得超过该位最值 { m=0;temp=0; for(m;m<=n-1;m++) { c=i/pow(10,m); d=c%10; temp=temp+pow(d,n); if(temp==i && m==n-1) { printf("%d\n",i); } } } }

你可能感兴趣的:(;练习题,水仙花数,C语言,代码)