使用C++编写程序:
题目描述
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153 = 1 ^ 3 + 5 ^ 3 +3 ^ 3
现在要求输入一个三位数,判断该数是否是水仙花数,如果是,输出“yes”,否则输出“no”
输入
输入一个三位的正整数。
输出
输出“yes”或“no”。
样例输入 Copy
153
样例输出 Copy
yes
程序代码如下:
#include<iostream>
#include<cmath>
#define ElemType_U unsigned
using namespace std;
class NarciNum
{
public:
NarciNum(ElemType_U Num) :Number(Num) {};
void GetResult();
private:
ElemType_U Number;
};
inline void NarciNum::GetResult()
{
if(Number==pow(Number/100,3)+pow((Number/10)%10,3)+pow(Number%10,3))
cout<<"yes";
else
cout<<"no";
}
int main()
{
ElemType_U Number;
cin >> Number;
NarciNum N(Number);
N.GetResult();
return 0;
}