输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其各位数字立方和等于该数本身。例如153是水仙花数
#include <stdio.h>
#include <stdlib.h>
void cal()
{
for (int i = 100; i < 1000; i++)
{
//int temp = i;
int a = i % 10;
int b = i / 10 % 10;
int c = i / 100;
if (i == (a*a*a + b*b*b + c*c*c))
{
printf("%d ", i);
}
}
}
int main()
{
cal();
system("pause");
return 0;
}
答案
输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其各位数字立方和等于该数本身。例如153是水仙花数