Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 04 / Solutions / exercise06.cpp
diff options
context:
space:
mode:
Commitab31cac5ab5509785221d7420f54993b51fa8a7f (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 20:42:13 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 20:42:13 +0200
Files8354deccd2aafbe00acc860e34f1affb63f75f5f /Sem. 04/Solutions/exercise06.cpp
Introduction_to_programming_FMI-ab31cac5ab5509785221d7420f54993b51fa8a7f.tar
Introduction_to_programming_FMI-ab31cac5ab5509785221d7420f54993b51fa8a7f.tar.gz
Introduction_to_programming_FMI-ab31cac5ab5509785221d7420f54993b51fa8a7f.zip
Parent91c58192153aec6803de90951e2d72b36fcc4e16 (diff)
Solved all unsolved exercises from Seminar 4
1 files changed, 38 insertions, 0 deletions
-rw-r--r--Sem. 04/Solutions/exercise06.cpp38
diff --git a/Sem. 04/Solutions/exercise06.cpp b/Sem. 04/Solutions/exercise06.cpp
new file mode 100644
index 0000000..3ced4c3
--- /dev/null
+++ b/Sem. 04/Solutions/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);
+}