水仙花数,c语言程序设计

编写一个函数f(int x) ,该函数的功能是实现x是一个四位的水仙花数(该数的各个数位上的数字的四次方和等于该数);然后主函数调用该函数输出所有的四位水仙花数。

#include<stdio.h>

int f(int x){
    int t,res = 0;
    while (x>0){
        t = x%10;
        res += t*t*t*t;
        x /= 10;
    }
    return res;
}

int main()
{
    for(int i=1000;i<10000;i++){
        if (i==f(i))
            printf("%d\n",i);
    }
    
    return 0;
}

结果:
1634
8208
9474