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


CARD FUNC Factorial(INT n BYTE POINTER err)
  CARD i,res
 
  IF n<0 THEN
    err^=1 RETURN (0)
  ELSEIF n>8 THEN
    err^=2 RETURN (0)
  FI
 
  res=1
  FOR i=2 TO n
  DO 
    res=res*i
  OD
 
  err^=0
RETURN (res)
 
PROC Main()
  INT i,f
  BYTE err
 
  FOR i=-2 TO 10
  DO 
    f=Factorial(i,@err)
 
    IF err=0 THEN
      PrintF("%I!=%U%E",i,f)
    ELSEIF err=1 THEN
      PrintF("%I is negative value%E",i)
    ELSE
      PrintF("%I! is to big%E",i)
    FI
  OD
RETURN