836
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
// prints out prime numbers from 2 to 100
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
end := 100;
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
n := 2;
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
while (n < end) do {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
f := 2;
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
tmp := 0;
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
while ((f < n / 2 + 1) && (tmp == 0)) do {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
if ((n / f) * f == n) then { tmp := 1 } else { skip };
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
f := f + 1
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
};
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
if (tmp == 0) then { write(n) } else { skip };
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
n := n + 1
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
} |