primes/src/Main.m3

46 lines
626 B
Plaintext
Raw Normal View History

2011-03-08 07:01:27 +00:00
(* Modula-3 version of a Prime Number Finder
haplo@mindstab.net *)
MODULE Main;
IMPORT IO;
IMPORT Math;
IMPORT Params;
IMPORT Scan;
PROCEDURE Main() =
VAR i, cnt, max, sq, isp : INTEGER;
BEGIN
IF Params.Count < 2 THEN
IO.Put("Useage: primesm3 [Max Num]\n");
RETURN
END;
max := Scan.Int(Params.Get(Params.Count-1));
FOR cnt := 3 TO max BY +2 DO
sq := ROUND(Math.sqrt(FLOAT(cnt, LONGREAL)));
isp := 1;
FOR i := 3 TO sq BY +2 DO
IF cnt MOD i = 0 THEN
isp := 0;
EXIT;
END;
END;
IF isp = 1 THEN
IO.PutInt(cnt);
IO.Put("\n");
END;
END;
END Main;
BEGIN
Main();
END Main.