本文发布于 1614 天前,最后更新于 1457 天前,其中的信息可能已经有所发展或是发生改变。
#include "bits/stdc++.h"
using namespace std;
int judge_profect_num(int a)
{
int s = 0;
int i = 1;
while(i<(a/2+1))
{
if(a%i==0)
{
s+=i;
}
i++;
}
if(s==a) cout << "是的,是完数!";
else cout << "Sorry,不是完数!";
return 0;
}
int judge_flower_num(int b)
{
int x,y,z;
x = b%10;//个位
y = b/10%10;//十位
z = b/100%10;//百位
int num = pow(x,3) + pow (y,3) + pow(z,3);
if(num == b) cout << "是的,是水仙花数!";
else cout << "Sorry,不是水仙花数!";
return 0;
}
int judge_prime(int c)
{
for(int i = 2; i*i <= c; i++)
{
if(c % i == 0)
{
cout << "Sorry,不是质数,是素数!";
return 0;
}
}
cout << "不是素数,是质数!";
return 0;
}
int main()
{
cout << "请以此输入要判断的完数,水仙花数(三位数),素数。"<<endl;
cout << "请用空格隔开三个数"<< endl <<endl;
int a,b,c;
cin >> a >> b >> c;
judge_profect_num(a);
cout << endl;
judge_flower_num(b);
cout << endl;
judge_prime(c);
return 0;
}