#include <stdio.h>
#include <math.h>
int main()
{
int n = 0;
int tmp = 0;
for (n = 0; n <= 100000; n++)
{
tmp = n;
int count = 1;
while (tmp / 10)
{
count++;
tmp /= 10;
}
int sum = 0;
tmp = n;
while (tmp)
{
sum += pow(tmp % 10, count);
tmp /= 10;
}
if (sum == n)
{
printf("%d ", n);
}
}
return 0;
}
注意:数字位数的判断,和循环条件的灵活使用