Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 04 / exercise06.cpp
diff options
context:
space:
mode:
Commitdf27afaa9a5bb3d3a168b57c8c407d25e553f13f (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 20:51:17 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 20:51:17 +0200
Files7c4232200c0df0a9c9078ed4fc531544cbcfd650 /Year 1/Programming introduction/Solutions Sem. 04/exercise06.cpp
uni-projects-df27afaa9a5bb3d3a168b57c8c407d25e553f13f.tar
uni-projects-df27afaa9a5bb3d3a168b57c8c407d25e553f13f.tar.gz
uni-projects-df27afaa9a5bb3d3a168b57c8c407d25e553f13f.zip
Parented07ca36f9b87410838d6657eefd6ee9db686baa (diff)
Added my solutions to Sem. 04 exercises
1 files changed, 38 insertions, 0 deletions
-rw-r--r--Year 1/Programming introduction/Solutions Sem. 04/exercise06.cpp38
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 <iostream>
+#include <cmath>
+
+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);
+}