#include <iostream>
using namespace std;
int main()
{
// 打印所有的水仙花数
// 水仙花数:一个三位数,其各位数字的立方和等于该数本身
int i, a, b, c;
cout << "水仙花数:" << endl;
for (i=100; i<1000; i++){
a = i/100;
b = i/10%10;
c = i%10;
if (i==a*a*a+b*b*b+c*c*c){
cout << i << " ";
}
}
return 0;
}
运行结果如下: