perm filename PRIMES.SAI[S,AIL] blob
sn#073858 filedate 1973-11-26 generic text, type T, neo UTF8
begin "PRIMES"
integer array primes[1:100];
integer number!of!primes,test,temp,i;
label print,die;
define crlf="'12&'15";
boolean procedure prime(integer n);
begin
for i←1 step 1 until number!of!primes do
if (n mod primes[i])=0 then return(false);
return(true);
end;
open(1,"tty",1,0,1,temp,temp,temp);
primes[1]←2;
number!of!primes←1;
for test←3 step 2 until 1000 do
if prime(test) then
begin
if (number!of!primes←number!of!primes+1) > 100 then go print;
primes[number!of!primes]←test;
end;
out(1,"there are more than 100 primes < 1000"&crlf);
go die;
print:
out(1,"the first 100 primes are:"&crlf);
for i←1 step 1 until 100 do
out(1,cvs(i)&" "&cvs(primes[i])&crlf);
close(1);
die:
end "PRIMES";