所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个“水仙花数”,1*1*1 + 5*5*5 + 3*3*3 = 1 + 125 + 27 = 153
int a, b, c;
for (int i = 100; i < 1000; i++)
{
a = i % 100 / 10;
b = i % 10;
c = i / 100;
if ((a * a * a + b * b * b + c * c * c) == i)
{
Console.WriteLine(i);
}
}
|