代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int i, temp, n, sum, count = 0;
for (i = 1000; i <= 9999; i++) {
temp = i;
sum = 0;
while (temp != 0) {
n = temp % 10;
sum += (int)pow((double)n, 4);
temp /= 10;
}
if (sum == i) {
printf("%d ", i);
count++;
}
}
printf("\n四位数水仙数有 %d 个。\n", count);
system("pause");
return 0;
}
运行结果: