所谓“水仙花数”是指一个3位数,其各位数字立方和等于该书本身。
例如,153是水仙花数,因为153=。
源代码如下:
#include <stdio.h>
int main()
{
int x,a,b,c,y;
x=100;
while (x<=999)
{
a=x/100;
b=x/10;
c=x/1;
y=a*a*a+(b-a*10)*(b-a*10)*(b-a*10)+(c-b*10)*(c-b*10)*(c-b*10);
if(x==y)
printf("%d是水仙花数\n",y);
x++;
}
return 0;
}