#include <iostream> #include<cmath> using namespace std; int main() { int a,b,c; //定义百十个位数的变量 // 开始循环判断水仙花数 for(int i = 100 ;i <1000; i ++){ a = i/100; // 百位 123/100 = 1 b = i/10%10; // 十位 123/10=12 => 12%10 = 2 c = i%10; // 个位 123%10 =3 if(i == pow(a,3)+pow(b,3)+pow(c,3)){ // 满足条件输出 cout<<i<<endl; } } return 0; }
水仙花数