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


var int: factorial(int: n) =
  let {
    array[0..n] of var int: factorial;
    constraint forall(a in 0..n)(
      factorial[a] == if (a == 0) then
        1
      else
        a*factorial[a-1]
      endif
  )} in factorial[n];
 
var int: fac = factorial(6);
solve satisfy;
output [show(fac),"\n"];