int Sum(int tmp, int n)
{
int j = 1;
int sum = 0;
while (tmp)
{
int ret = 1;
int tmp2 = 0;
for (j = 1; j <= n; j++)
{
tmp2 = ret * tmp % 10;
}
sum += tmp2;
tmp /= 10;
}
return sum;
}
int main()
{
int i = 0;
for (i = 0; i <= 100000; i++)
{
//判断i是否为水仙花数(自幂数)
//1,计算i的 n位数;
int n = 1;
int tmp = i;
int sum = 0;
while (tmp > 9)
{
n++;
tmp = tmp / 10;
}
tmp = i;
sum = Sum(tmp, n);
//2,计算i的每一位数n次方之和 sum
/*tmp = i;
while (tmp)
{
sum += (int)pow(tmp % 10, n);
tmp /= 10;
}*/
//3,比较i == sum
if (i == sum)
{
printf("%d ", i);
}
}
return 0;
}