求水仙花数写法的详细解释
# include <stdio.h># include <math.h>
bool IsNarcissus (int number);
int n=3;
int main()
{
int i;
for(i=pow(10,n-1); i<pow(10,n); ++i)
{
if (IsNarcissus (i))
{
printf("%d \n",i);
}
}
return 0;
}
bool IsNarcissus (int number)
{
int sum=0;
int x=number;
while(x!=0)
{
sum += pow((x%10),n);
x /= 10;
}
if (sum == number)
{
return true;
}
else
{
return false;
}
}
求写法的详细解释