dos_compilers/Microsoft Pascal v3.31/PRIMES.PAS
2024-07-01 06:10:13 -07:00

31 lines
770 B
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ Prime number generator }
{ Generates all the primes between 0 and 10000 }
program primes(output);
var
prime: integer;
rprime: real4;
i: integer;
sqrtp: integer;
notprime: boolean;
begin
writeln(' 2');
writeln(' 3');
prime := 5;
repeat
rprime := prime;
sqrtp := trunc(sqrt(rprime) + 1.0);
i := 1;
notprime := false;
while (i < sqrtp) and (not notprime) do
begin
i := i + 2;
notprime := (prime mod i = 0);
end;
if (not notprime) then writeln(prime:6);
prime := prime + 2;
until (prime > 10000);
end.