cwtests/cw03/primes.while
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 29 Oct 2023 13:05:09 +0000
changeset 948 6bb67c2dcfd3
parent 852 8706b846a3e0
permissions -rw-r--r--
updated

// prints out prime numbers from 2 to 100 

end := 100;
n := 2;
while (n < end) do {
  f := 2;
  tmp := 0;
  while ((f < n / 2 + 1) && (tmp == 0)) do {
    if ((n / f) * f == n) then  { tmp := 1 } else { skip };
    f := f + 1
  };
  if (tmp == 0) then { write(n); write("\n") } else { skip };
  n  := n + 1
}