3位数的水仙花数C++

方法一:

#include

using namespace std;

int main()

{

int a, b, c;

for (a = 1; a <= 9; a++)

for (b = 0; b <= 9; b++)

for (c = 0; c <= 9; c++)

if (a * 100 + b * 10 + c == a*a*a + b*b*b + c*c*c)

cout << "水仙花数有:" << a * 100 + b * 10 + c << endl;

return 0;

}

方法二:

#include

using namespace std;

int main()

{int i,j,k,n;

for (n=100;n<1000;n++)

{

i=n/100;

j=n/10-i*10;

k=n%10;

if (n == i*i*i + j*j*j + k*k*k)

cout<<"水仙花数是:"<

}

cout<

return 0;

}

你可能感兴趣的:(3位数的水仙花数C++)