You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
710 B

{ Pascal version of a Prime Number Finder
Built with fpc (Free Pascal) www.freepascal.org
haplo@mindstab.net }
program primes;
var isPrime : Integer;
var test : Real;
var MAX, cnt, i : LongInt;
begin
if ARGC <= 1 then begin
WriteLn('Useage: primespas [Max Num]');
exit;
end;
{MAX := Str2Int(ARGV[1]);}
Val(ARGV[1], MAX, cnt);
if MAX < 1 then begin
WriteLn('Invalid Max Num');
exit;
end;
cnt := 3;
while cnt <= MAX do
begin
test := sqrt(cnt);
isPrime := 1;
i := 3;
while i <= test do
begin
if (cnt mod i) = 0 then begin
isPrime := 0;
break;
end;
i := i + 2;
end;
if not (isPrime = 0) then
begin
WriteLn(cnt);
end;
cnt := cnt +2;
end;
end.