Primes by Trial Division - Pascal

24 April 2017

I'm not sure how portable this will prove.

For Berkeley Pascal (as implemented on, e.g., VAX Ultrix 4 or SPARCworks Pascal), convert all keywords to lower-case.

PROGRAM nPrimes (OUTPUT);

(* CONST NumPrimes = 100; *)
CONST NumPrimes = 1000;
(* CONST NumPrimes = 10000; *)

VAR Count, Index, Found : INTEGER;
    Primes : ARRAY [1..NumPrimes] OF INTEGER;
    
BEGIN

	Found := 0;
	Count := 2;
	
	WHILE Found < NumPrimes DO
	BEGIN

		Found := Found + 1;
		Primes[Found] := Count;
		WRITELN(Count);
		Count := Count + 1;
		
		Index := 1;
		REPEAT
			IF Count MOD Primes[Index] = 0 THEN
			BEGIN
				Count := Count + 1;
				Index := 0;
			END;
			Index := Index + 1;
		UNTIL Index > Found;
	
	END;
	
END.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026

Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Primes Benchmark Source

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

Primes Benchmark Results

Other Pascal Family

Ada-83

Ada-95

Modula-2

TopSpeed Modula-2

Oberon

Oberon-2

Active Oberon

Pascal

VS Pascal