kolibrios-fun/programs/develop/oberon07/Samples/Windows/Console/fact.ob07
maxcodehack 2f54c7de00 Update oberon07 from akron1's github
git-svn-id: svn://kolibrios.org@8097 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-10-13 07:58:51 +00:00

59 lines
888 B
Plaintext

(*
adapted to Oberon-07 by 0CodErr, KolibriOS team
*)
(*
* Written by Andrew Cadach
*
* Recursive (extremely uneficient:-) implementation of factorial
*
* n * (n-1)!, n <> 0
* By definition, n! =
* 1, n = 0
*
*)
MODULE fact;
IMPORT In, Out, Console;
CONST
MAX_INTEGER = ROR(-2, 1);
VAR
i, r: INTEGER;
PROCEDURE f (n: INTEGER): INTEGER;
VAR
Res: INTEGER;
BEGIN
IF n = 0 THEN
Res := 1
ELSE
Res := n * f (n - 1)
END
RETURN Res
END f;
BEGIN
Console.open;
i := 0;
REPEAT
r := f(i);
Out.String ("The factorial of ");
Out.Int (i, 2);
Out.String (" is ");
Out.Int (r, 0);
Out.Ln;
INC(i)
UNTIL r >= MAX_INTEGER DIV i;
In.Ln;
Console.exit(TRUE)
END fact.