#includeusing namespace std; int main() { //打印出所有的三位数 int num = 100; int a = 0;//个位 int b = 0;//十位 int c = 0;//百位 do { //从所有三位数字中找到水仙花数 a = num % 10; //得到个位数 b = num / 10 % 10; //得到十位数 c = num / 100; //得到百位数 if (a*a*a + b*b*b + c*c*c == num) //如果是水仙花数,就打印 { cout << num << endl; } num++; } while (num < 1000); //求出所有水仙花数 system("pause"); return 0; }



