Modula-2

Modula-2 is a Wirth programming language. One among many. It is quite similar to Pascal. Modula-2 requires fewer "BEGIN" statements than Pascal.

This program compiles and runs under the Native XDS-x86 Personal Edition Modula-2/Oberon-2 Development Toolset.


MODULE SieveE;



FROM STextIO IMPORT WriteLn,WriteString;


FROM SWholeIO IMPORT WriteInt;



VAR Candidates : ARRAY [0..999] OF INTEGER;


i,j : INTEGER;



BEGIN


FOR i := 0 TO 999 DO


Candidates[i] := 1;


END;


Candidates[0] := 0;


Candidates[1] := 0;


i := 0;


WHILE i<1000 DO


WHILE (i<1000) AND (Candidates[i] = 0) DO


i := i+1;


END;


IF i<1000 THEN


j := 2;


WHILE j*i < 1000 DO


Candidates[j*i] := 0;


j := j+1;


END;


i := i+1;


END


END;


FOR i := 0 TO 999 DO


IF Candidates[i] <> 0 THEN


WriteInt(i,3);


WriteString(' is prime');


WriteLn;


END


END


END SieveE.

Click Here for the actual code.