From df27afaa9a5bb3d3a168b57c8c407d25e553f13f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 3 Nov 2021 20:51:17 +0200 Subject: Added my solutions to Sem. 04 exercises --- .../Solutions Sem. 04/exercise06.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Year 1/Programming introduction/Solutions Sem. 04/exercise06.cpp (limited to 'Year 1/Programming introduction/Solutions Sem. 04/exercise06.cpp') diff --git a/Year 1/Programming introduction/Solutions Sem. 04/exercise06.cpp b/Year 1/Programming introduction/Solutions Sem. 04/exercise06.cpp new file mode 100644 index 0000000..3ced4c3 --- /dev/null +++ b/Year 1/Programming introduction/Solutions Sem. 04/exercise06.cpp @@ -0,0 +1,38 @@ +#include +#include + +using namespace std; + +bool isPowerOfSomething(int n) +{ + double rootOfN = sqrt(n); + for (int i = 2; i <= rootOfN; i++) + { + if (n % i == 0) + { + while (n % i == 0) + n /= i; + + return n == 1; + } + } + return false; // Obligatory default case +} + +void powerNumbersBetween(int a, int b) +{ + for (int i = a; i <= b; i++) + { + if (isPowerOfSomething(i)) + cout << i << " "; + } + cout << endl; +} + +int main() +{ + int a, b; + cin >> a >> b; + + powerNumbersBetween(a, b); +} -- cgit v1.3.1-26-gb76a