ตัว |
PROGRAM PRIMELIST1; CONST size = 1000; (* This is the maximum number of primes to be found, *) (* and can be adjusted as required *) VAR n: extended; i,j,no_primes: integer; p: array[1..size] of extended; pass: boolean; BEGIN write ('Number of primes = ? ') readln (no_primes); (* This is < size *) p[1]:= 2; p[2]:= 3; writeln (2,',',3); n:=3; FOR i:= 3 TO no_primes DO BEGIN BEGIN pass:= NOT(n = p[ j ] * INT(n/p[ j ] )); (* The number n passes this test if it is not *) (* divisble by the jth prime *) j:= j + 1 END; BEGIN p[ i ]:= n; write(',',n:0:0); (* and also written to the screen *) END; END; END. |
ที่มา: รศ. ยืน ภู่วรวรรณ, สำนักบริการคอมพิวเตอร์ มหาวิทยาลัย |