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 }
本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15089102.html