MODULE Factorial; FROM InOut IMPORT WriteCard, WriteLn; PROCEDURE Fact(n:CARDINAL):CARDINAL; VAR nfact: CARDINAL; BEGIN IF n > 8 THEN RETURN 0 END; nfact:=1; FOR n:=n TO 1 BY -1 DO nfact:=nfact*n END; RETURN nfact; END Fact; VAR i:CARDINAL; BEGIN FOR i:=0 TO 8 DO WriteCard(i,3); WriteCard(Fact(i),12); WriteLn END END Factorial.
0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320