From 796b6a268a4010e703e8da7290f1c40d084a63fe Mon Sep 17 00:00:00 2001 From: VD Date: Thu, 30 Jul 2020 14:31:02 +0300 Subject: [PATCH] Erastofen algoritm task (#2) * Erastofen Grid * Erastofen upgradet * Erastofen app CPP language --- Eratosfen/Erastofen.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Eratosfen/Erastofen.cpp diff --git a/Eratosfen/Erastofen.cpp b/Eratosfen/Erastofen.cpp new file mode 100644 index 0000000..c80e2d1 --- /dev/null +++ b/Eratosfen/Erastofen.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +int main() +{ + int n; + cout << "n= "; + cin >> n; + int *a = new int[n + 1]; + for (int i = 0; i < n + 1; i++) + a[i] = i; + for (int p = 2; p < n + 1; p++) + { + if (a[p] != 0) + { + cout << a[p] << endl; + for (int j = p*p; j < n + 1; j += p) + a[j] = 0; + } + } + cin.get(); cin.get(); +}