Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 6 / Task_1(without functions).cpp
diff options
context:
space:
mode:
Commit1697dfff314ccbbe1457e95ed736aaa296bfddcc (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2020-11-17 19:24:32 +0200
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2020-11-17 19:24:32 +0200
Filesa6b75276e39a08dc7a4fb7f1544ed1b353af6226 /Sem. 6/Task_1(without functions).cpp
Introduction_to_programming_FMI-1697dfff314ccbbe1457e95ed736aaa296bfddcc.tar
Introduction_to_programming_FMI-1697dfff314ccbbe1457e95ed736aaa296bfddcc.tar.gz
Introduction_to_programming_FMI-1697dfff314ccbbe1457e95ed736aaa296bfddcc.zip
Parentcd8af20ed63c37387a13e7016ee51a0058416ad6 (diff)
added sem 6 examples
1 files changed, 40 insertions, 0 deletions
-rw-r--r--Sem. 6/Task_1(without functions).cpp40
diff --git a/Sem. 6/Task_1(without functions).cpp b/Sem. 6/Task_1(without functions).cpp
new file mode 100644
index 0000000..9e5bcdb
--- /dev/null
+++ b/Sem. 6/Task_1(without functions).cpp
@@ -0,0 +1,40 @@
+#include <iostream>
+using namespace std;
+
+int main()
+{
+ int n;
+ cin >> n;
+
+ for (int i = 6; i <= n; i+=6)
+ {
+ int firstNumToCheck = i - 1, secondNumToCheck = i + 1;
+
+ double temp = sqrt(firstNumToCheck);
+ bool isFirstNumPrime = true;
+ for (int j = 2; j <= temp; j++)
+ {
+ if (firstNumToCheck % j == 0)
+ {
+ isFirstNumPrime = false;
+ break;
+ }
+ }
+
+ if (!isFirstNumPrime)
+ continue;
+ double temp2 = sqrt(secondNumToCheck);
+ bool isSecondNumPrime = true;
+ for (int j = 2; j <= temp2; j++)
+ {
+ if (secondNumToCheck % j == 0)
+ {
+ isSecondNumPrime = false;
+ break;
+ }
+ }
+ if (isSecondNumPrime)
+ cout << firstNumToCheck << " " << secondNumToCheck << endl;
+ }
+
+} \ No newline at end of file