progs/primes.while
author Christian Urban <urbanc@in.tum.de>
Sun, 27 Oct 2019 13:32:15 +0000
changeset 674 e0a41a1f24cf
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
674
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// prints out prime numbers from
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
// 2 to 100 (end)
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
end := 100;
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
n := 2;
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
while (n < end) do {
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  f := 2;
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  tmp := 0;
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  while ((f < n / 2 + 1) && (tmp == 0)) do {
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
    if ((n / f) * f == n) then  { tmp := 1 } else { skip };
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
    f := f + 1
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  };
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  if (tmp == 0) then { write(n) } else { skip };
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  n  := n + 1
e0a41a1f24cf updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
}