size : 1410
uploaded_on : Sat Jun 20 00:00:00 1998
modified_on : Wed Dec 8 14:03:38 1999
title : Prime Numbers
org_filename : Prime.pas
author : Sam Hasinoff
authoremail :
description : Program to calculate prime numbers
keywords :
tested : Borland Pascal 7.0
submitted_by : The CKB Crew
submitted_by_email : ckb@netalive.org
uploaded_by : nobody
modified_by : nobody
owner : nobody
lang : pas
file-type : text/plain
category : pascal-alg-maths
__END_OF_HEADER__
Program Prime_Numbers;
Uses Crt;
Var
LoopNum,
Count,
MinPrime,
MaxPrime,
PrimeCount : LongInt; {The prime numbers to calculate must be within the}
Prime : Boolean; {range of a LongInt. }
max : String[20];
ECode : Integer;
Ch : Char;
begin
minprime := 0;
maxprime := 0;
ClrScr;
Write('Lower limit For prime number search [1]: ');
readln(max);
val(max, minprime, ECode);
if (minprime < 1) then
minprime := 1;
Repeat
GotoXY(1, 2);
ClrEol;
Write('Upper limit: ');
readln(max);
val(max, maxprime, ECode);
Until (maxprime > minprime);
WriteLn;
PrimeCount := 0;
For LoopNum := minprime to maxprime do
begin
prime := True;
Count := 2;
While (Count <= (LoopNum div 2)) and (Prime) do
begin
if (LoopNum mod Count = 0) then
prime := False;
Inc(Count);
end;
if (Prime) then
begin
Write('[');
TextColor(white);
Write(LoopNum);
TextColor(lightgray);
Write('] ');
Inc(PrimeCount);
if WhereX > 75 then
Write(#13#10);
end;
if WhereY = 24 then
begin
Write('-- Press any key to continue... Esc = Quit --');
Ch:=ReadKey;
If Ch=#27 Then Break;
ClrScr;
end;
prime := False;
end;
Write(#13#10#10);
Writeln(PrimeCount, ' primes found.', #13#10);
end.