05-08 水仙花数
freeWings2017:
【参考代码】
#include<stdio.h>
#include<math.h>
int main()
{
int n,a,b,c,s;
printf("水仙花数有:");
for(n=100;n<=999;n++)
{
a=n/100;
b=n/10%10;
c=n%10;
//s=a*a*a+b*b*b+c*c*c;
s=pow(a,3)+pow(b,3)+pow(c,3);
if(s==n)
printf("%d,",n);
}
printf("\b.");
return 0;
}
【运行结果】
水仙花数有:153,370,371,407.
--------------------------------
习题 第五版 C程序设计 谭浩强