|
|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 1280 (0x500)
Types: TextFile
Names: »ERATOSTH.PAS«
└─⟦092727b26⟧ Bits:30005927 Demoprogrammer til Pascal bog (Jet-80)
└─⟦this⟧ »ERATOSTH.PAS«
└─⟦3702e543b⟧ Bits:30003064 Demoprogrammer A-J til Pascal bog
└─⟦this⟧ »ERATOSTH.PAS«
PROGRAM eratosth;
TYPE
arraytype = ARRAY(.1 .. 16384.) OF BOOLEAN;
VAR
tab : arraytype; (* tab(.i.) repræsenterer det ulige tal 2 * i + 1 *)
graense, graense2, graense3, i, j, k : INTEGER;
BEGIN
WRITE(CLRHOM);
WRITE('Indtast øvre grænse (max: 32767): '); READLN(graense);
graense2 := graense DIV 2;
graense3 := graense DIV 3 + 1;
FOR i := 1 TO graense2 DO
tab(.i.) := TRUE;
WRITELN;
IF graense > 1
THEN WRITE(2 : 8);
FOR i := 1 TO graense2 DO
IF tab(.i.)
THEN
BEGIN
j := i + i + 1; (* j er et primtal *)
IF j <= graense
THEN WRITE(j : 8);
IF j <= graense3 (* nu slettes de ulige multipla af j - *)
THEN (* det er netop hvert j. element i tab *)
BEGIN
k := i + j; (* tab(.k.) er dem, der skal slettes *)
WHILE k <= graense2 DO
BEGIN
tab(.k.) := FALSE;
k := k + j;
END;
END;
END;
WRITELN;
END.
x«eof»