若三位数abc满足abc=a*a*a+b*b*b+c*c*c,则该数为水仙花数。
#include <stdio.h>
#include <stdlib.h>#include <math.h>
#include <time.h>
int waterFlower(int n)
{
int tempFlower = 0;
int a,b,c;
a=n/100;
b=n/10%10;
c=n%10;
if(n==a*a*a+b*b*b+c*c*c)
{
tempFlower = n;
}
return tempFlower;
}
int main()
{
int i;
int flower;
for(i=100;i<=999;i++)
{
if(flower=waterFlower(i))
{
printf("%d\n",flower);
}
}
return 0;
}