Definitions

   The factorial of   0   (zero)   is defined as being   1   (unity).
   The   Factorial Function   of a positive integer,    n,    is defined as the product of the sequence:
                 n,   n-1,   n-2,   ...   1 



Task

Write a function to return the factorial of a number.

Solutions can be iterative or recursive.

Support for trapping negative    n    errors is optional.



Related task

   Primorial numbers


/* Note that ulong is 32 bits, so fac(12) is the largest
 * supported value. This is why the input parameter
 * is a byte. The parameters are all unsigned. */ 
proc nonrec fac(byte n) ulong:
    byte i;
    ulong rslt;
    rslt := 1;
    for i from 2 upto n do
        rslt := rslt * i
    od;
    rslt
corp
 
proc nonrec main() void:
    byte i;
    for i from 0 upto 12 do
        writeln(i:2, "! = ", fac(i):9)
    od
corp