From ab31cac5ab5509785221d7420f54993b51fa8a7f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 3 Nov 2021 20:42:13 +0200 Subject: Solved all unsolved exercises from Seminar 4 --- Sem. 04/Solutions/exercise05.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Sem. 04/Solutions/exercise05.cpp (limited to 'Sem. 04/Solutions/exercise05.cpp') diff --git a/Sem. 04/Solutions/exercise05.cpp b/Sem. 04/Solutions/exercise05.cpp new file mode 100644 index 0000000..cfe60e4 --- /dev/null +++ b/Sem. 04/Solutions/exercise05.cpp @@ -0,0 +1,33 @@ +#include +#include + +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); +} -- cgit v1.3.1-23-gd82d