primes/primes.pas

48 lines
710 B
Plaintext
Raw Permalink Normal View History

2011-03-08 08:01:27 +01:00
{ 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.