Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 04 / example1_with_functions.cpp
diff options
context:
space:
mode:
Commit7b48d82f74cfa2a8820cad4c50ca7a916458850a (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2021-11-02 14:32:57 +0200
Committer
 GitHub <noreply@github.com>
2021-11-02 14:32:57 +0200
Files3890948ef5a3dc7260c97b062f27585d8645c301 /Sem. 04/example1_with_functions.cpp
Introduction_to_programming_FMI-7b48d82f74cfa2a8820cad4c50ca7a916458850a.tar
Introduction_to_programming_FMI-7b48d82f74cfa2a8820cad4c50ca7a916458850a.tar.gz
Introduction_to_programming_FMI-7b48d82f74cfa2a8820cad4c50ca7a916458850a.zip
Parent72c9987765cf118b71bfdc9020e97bcf7f2a999a (diff)
Add files via upload
1 files changed, 27 insertions, 0 deletions
-rw-r--r--Sem. 04/example1_with_functions.cpp27
diff --git a/Sem. 04/example1_with_functions.cpp b/Sem. 04/example1_with_functions.cpp
new file mode 100644
index 0000000..f33b6b9
--- /dev/null
+++ b/Sem. 04/example1_with_functions.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+using namespace std;
+
+bool isPrime(int n)
+{
+ double temp = sqrt(n);
+
+ for (int i = 2; i <= temp; i++)
+ {
+ if (n % i == 0)
+ return false;
+ }
+
+ return true;
+}
+
+int main()
+{
+ int n;
+ cin >> n;
+
+ for (int i = 6; i < n; i += 6)
+ {
+ if (isPrime(i - 1) && isPrime(i + 1))
+ cout << i - 1 << " " << i + 1 << endl;
+ }
+} \ No newline at end of file