/*
Sieve finds all primes within a specific range. It is often used
as a benchmark application.
This finds all primes between 1 and n, where n is an input to the
program, and defaults to 5000.
*/
arg n /* accept input "n" */
if n = "" then n = 5000 /* implement default "n" of 5000 */
do i = 2 to n % 2 /* calculate */
do j = 2 to n % i /* all non-prime */
k = i * j /* values in that range. */
a.k = 0 /* mark all non-primes in an array. */
end
end
do i = 1 to n /* look through array */
if a.i \= 0 then say i /* display all primes found */
end