/* 有道题是输出所有的水仙花数,水仙花数是指一个3位数, 其各位数字的立方和等于该数本身。例如:153=1的3次方+5的3次方+3的3次方。 */ #include <iostream> #include <conio.h>
using namespace std;
#define TRIMP(x) (x)*(x)*(x)
int main() { cout<<"水仙花数有:"<<endl;
int b, c, d, tmp; b = c = d = 0; for(int n = 100; n<=999; ++n) { b = TRIMP(n/100); c = TRIMP((n%100)/10); d = TRIMP((n%100)%10); tmp = b + c + d; if(n == tmp) cout << n << endl; }
getch(); return 0; } 
|