题目:请输出所有水仙花数
水仙花数:指一个三位数,它的每一位上的数字的三次幂之和等于它本身
例如:153 = 1^3 + 5^3 + 3^3
#include <iostream>
/*
水仙花数:指一个三位数,它的每一位上的数字的三次幂之和等于它本身
例如:153 = 1^3 + 5^3 + 3^3
*/
using namespace std;
int main() {
for(int num = 100; num < 1000; num++) {
int first = num % 10; //个位数字
int second = ((num % 100) - first) / 10; //十位数字
int third = (num - first - second*10) / 100; //百位数字
if( (first*first*first + second*second*second + third*third*third) == num) {
cout << num << endl;
}
}
return 0;
}