C++水仙花 (如:153 = 1*1*1 + 5*5*5 + 3*3*3)

 1 #include <iostream>
 2 #include <ctime>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7 int num = 100;
 8     do
 9     {
10         int a = 0;
11         int b = 0;
12         int c = 0;
13 
14         a = num % 10;
15         b = num / 10 % 10;
16         c = num / 100;
17         if (a * a * a + b * b * b + c * c * c == num)   //如果是 就打印
18         {
19             cout << num << endl;
20         }
21         
22         num++;
23 
24     } while (num < 1000);
25 
26 
27 
28 
29 
30 
31 
32 
33     //system("pause");
34     return 0;
35 }

 

posted on 2021-08-02 11:11  Bytezero!  阅读(120)  评论(0编辑  收藏  举报