ตัว
อย่าง
โปรแกรม
การ
หา
เลข
จำนวน
เฉพาะ
วิธี
ที่
1
PROGRAM PRIMELIST1;
VAR
n,q,max:extended;
BEGIN
write(' Max = ? ');
(* Prompts you for the maximum: *)
(* all primes
<
max
are printed out *)
readln(max);
write('2');
n:=3;
WHILE n<=max DO
BEGIN
q:=3;
qdividesn:=false;
(* Initialization for the WHILE loop *)
WHILE (q*q<=n) AND NOT(qdividesn) DO
BEGIN
qdividesn:=(n=q*INT(n/q));
q:=q+2;
END;
IF NOT(qdividesn) THEN write(',',n:0:0);
n:=n+2;
END;
END.
ที่มา: รศ. ยืน ภู่วรวรรณ, สำนักบริการคอมพิวเตอร์ มหาวิทยาลัย
เกษตรศาสตร์