Factorial in ARIBAS

Example for versions ARIBAS 1.53

This example uses recursive factorial definition.

Function name fac is used because factorial is reserved function name in ARIBAS.

ARIBAS uses integer type for variables by default, so type declaration can be omitted.

group(0) is used to cancel digit groups separation by underscores during output.

function fac(n);
begin
    if (n = 0) then
        return(1);
    end;
    return(n * fac(n - 1));
end;

function fac0_16();
var n;
begin
    for n := 0 to 16 do
        writeln(n, "! = ", fac(n): group(0));
    end;
end;

fac0_16().