We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5a824de commit e3e52f1Copy full SHA for e3e52f1
Prime-Sieve(Linear).cpp
@@ -0,0 +1,34 @@
1
+#include <cstdio>
2
+#include <cstring>
3
+
4
+#define MAX 100
5
6
+using namespace std;
7
8
+bool isprime[MAX + 1];
9
+int prime[MAX], cnt;
10
11
+int main()
12
+{
13
+ memset(isprime, true, sizeof(isprime));
14
+ for (int i = 2; i <= MAX; i++)
15
+ {
16
+ if (isprime[i] == true)
17
18
+ prime[cnt++] = i;
19
+ }
20
+ for (int j = 0; j < cnt && i * prime[j] <= MAX; j++)
21
22
+ isprime[i * prime[j]] = false;
23
+ if (i % prime[j] == 0)
24
25
+ break;
26
27
28
29
+ for (int i = 0; i < cnt; i++)
30
31
+ printf("%d\n", prime[i]);
32
33
+ return 0;
34
+}
0 commit comments