#includestdiohvoid main int xs=0a; forx=100;x1000;x++ a=x; whilea!=0 s=s+a10a10a10; a=a10; ifx=s printf4dx; 输出水仙花数
#include<stdio.h> void main() { int x,s=0,a; for(x=100;x<1000;x++) { a=x; while(a!=0) { s=s+(a%10)(a%10)(a%10); a=a/10; } if(x==s) // 注意判断相等的符号 printf("%4d",x); s=0; // 每次循环结束需要将s清零 } }
原文地址: http://www.cveoy.top/t/topic/dHLW 著作权归作者所有。请勿转载和采集!