Description
打印出所有"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该本身。例如:153是一个水仙花数,因为153=1^3+5^3+3^3。 Output:
153 370 371 407
Input
无
Output
所有的水仙花数,从小的开始。每行一个
Sample Input
Sample Output
HINT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <iostream>
using
namespace
std;
int
main()
{
int
n,a,b,c;
for
(n=100;n<1000;n++)
{
a=n/100; //分别获取百位、十位、个位,进行检验
b=n/10-a*10;
c=n%10;
if
(n==a*a*a+b*b*b+c*c*c) cout<<n<<endl;
else
continue
;
}
return
0;
}
/**************************************************************
Problem: 1036
User: 201358501133
Language: C++
Result: Accepted
Time:0 ms
Memory:1264 kb
****************************************************************/
|