#include <stdio.h>
#include <math.h>
int main(){
int i=1000;
int g,s,b,q;
printf("以下数为水仙花数:\n");
for(i=1000;i<9999;i++)
{
//取千位
q=i/1000;
//取百位
b=i%1000/100;
//取十位
s=i%1000%100/10;
//取个位
g=i%1000%100%10;
if(pow(q,4)+pow(b,4)+pow(s,4)+pow(g,4)==i)
printf("%d\n",i);
}
}
运行结果:
以下数为水仙花数:
1634
8208
9474