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


            NORMAL MODE IS INTEGER
 
          R   CALCULATE FACTORIAL OF N 
            INTERNAL FUNCTION(N)
            ENTRY TO FACT.
            RES = 1
            THROUGH FACMUL, FOR MUL = 2, 1, MUL.G.N
FACMUL      RES = RES * MUL
            FUNCTION RETURN RES
            END OF FUNCTION
 
          R   USE THE FUNCTION TO PRINT 0! THROUGH 12!
            VECTOR VALUES FMT = $I2,6H ! IS ,I9*$
            THROUGH PRNFAC, FOR NUM = 0, 1, NUM.G.12
PRNFAC      PRINT FORMAT FMT, NUM, FACT.(NUM)
 
            END OF PROGRAM