Factorial in Seed7

Example for versions Seed7 2012-01-01

This example uses recursive factorial definition. Factorial values are stored as bigInteger, so there is no overflow.

$ include "seed7_05.s7i";
  include "bigint.s7i";

const func bigInteger: factorial (in var bigInteger: n) is func
result
    var bigInteger: result is 1_;
begin
    if n = 0_ then
        result := 1_;
    else
        result := n * factorial(n - 1_);
    end if;
end func;

const proc: main is func
local
    var integer: n is 0;
begin
    for n range 0 to 16 do
        write(n); 
        write("! = ");
        write(factorial(bigInteger conv n)); 
        writeln;
    end for;
end func;