#include<iostream>
#include<cmath>
using namespace std;
//写一个函数验证哥德巴猜想
bool prime(int n)
{
int count = 0;
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
count++;
if (count == 0)
return true;
else return false;
}
void gotbaha(int n)
{
for (int i = 3; i <= n; i++)
for (int j = 3; j <= n / 2; j++)
if (prime(i) && prime(j))
if (i + j == n)
cout << n << "=" << i << "+" << j << endl;
}
int main()
{
int n;
cout << "请输入一个不小于6的偶数:";
cin >> n;
gotbaha(n);
return 0;
}
谭浩强c++第三版4-7
最新推荐文章于 2020-09-02 23:27:29 发布