水仙花数
水仙花数是指一个 3(n)位数),它的每个位上的数字的 n 次幂之和等于它本身
考虑得到100-999所有的数,然后在判断是否是水仙花数
重点在于取模运算,取模得到一个数的个位、十位、百位数
#include <iostream>
using namespace std;
int main()
{
int a = 0;
int b = 0;
int c = 0;
int n = 0;
n = 100;
do {
a = n / 100;
b = (n / 10) % 10;
c = n % 10;
if (n == a * a * a + b * b * b + c * c * c )
{
cout << n << endl;
}
n++;
} while(n < 1000);
system("pause");
return 0;
}