题目:求水仙花数,水仙花指一个3位数,其各位数字立方和等于本身。例如153是水仙花数,因为 153 = 13 +53+33。
#include <stdio.h>
#include <math.h>
#define N 100
int main()
{
int count = 1;
int hundred;
int ten;
int ge;
for (int i = 100; i < 1000; i++)
{
hundred = i / 100;
ten = i / 10 % 10;
ge = i % 10;
if (i == pow(hundred, 3) + pow(ten, 3) + pow(ge, 3))
{
printf("%5d", i);
count++;
}
}
return 0;
}