-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEratos.mj.txt
More file actions
56 lines (51 loc) · 828 Bytes
/
Copy pathEratos.mj.txt
File metadata and controls
56 lines (51 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
program Eratos
char[] sieve;
int max; // maximum prime to be found
int npp; // numbers per page
{
void put(int x)
{
if (npp == 10) {
print(chr(13));
print(chr(10));
npp = 0;
}
print(x, 5);
npp = npp + 1;
}
void found(int x)
int i;
{
put(x);
i = x;
while (i <= max) {
sieve[i] = 'o';
i = i + x;
}
}
void main()
int i, ready;
{
read(max);
npp = 0;
sieve = new char[max+1];
i = 0;
while (i <= max) {
sieve[i] = 'x'; i = i + 1;
}
i = 2;
while (i <= max) {
found(i);
ready = 0;
while(ready == 0) {
if (i > max) {
ready = 1;
}else if (sieve[i] == 'x'){
ready = 1;
}else{
i = i + 1;
}
}
}
}
}