46 lines
626 B
Plaintext
46 lines
626 B
Plaintext
|
(* 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.
|