//求100~999之间的水仙花数 水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。 (例如:1^3 + 5^3+ 3^3 = 153) #include<stdio.h> #include<math.h> int main() { int i=0; int sum=0; int tmp; for(i=100;i<1000;i++) { tmp=i; sum=0; while(tmp) { sum+=pow((tmp%10),3); tmp/=10; } if(sum==i) { printf("%d\n",i); } } system("pause"); return 0; }
程序运行结果如下:
原文:http://760470897.blog.51cto.com/10696844/1705287