Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 04 / Solutions / exercise05.cpp
blob: cfe60e41a2723c6268e98d6aad535637c118ab0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <cmath>

using namespace std;

// Taken from exercise04.cpp
bool isPrime(int n)
{
	double rootOfN = sqrt(n);
	for (int i = 2; i <= rootOfN; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}

void printPrimeNumberPairs(int n)
{
	for (int i = 2; i <= n / 2; i++)
	{
		if (isPrime(i) && isPrime(n - i))
			cout << i << ", " << n - i << endl;
	}
}

int main()
{
	int n;
	cin >> n;

	printPrimeNumberPairs(n);
}