编写函数,使用指针作为函数的参数,判断两个正整数之和是否为素数,并在主函数中调用
问题补充:
用C++编写
最佳答案
#include <iostream>
#include <cmath>
using namespace std;
void func(int *a,int *b)
{
int sum=*a+*b;
bool f=true;
for(int i=2;i<=sqrt(sum);i++)
if (sum%i==0)
{
f=false;
break;
}
if(f)
cout << *a << "+" << *b <<"的和为素数" <<endl;
else
cout << *a << "+" << *b <<"的和不是素数" <<endl;
}
int main()
{
int a,b;
cin >> a >> b;
func(&a,&b);
return 0;
}
最佳答案由网友 whoami1978 提供
其他回答
暂无其它回答!