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


mata
real scalar function fact1(real scalar n) {
	if (n<2) return(1)
	else return(fact1(n-1)*n)
}
 
real scalar function fact2(real scalar n) {
	a=1
	for (i=2;i<=n;i++) a=a*i
	return(a)
}
 
printf("%f\n",fact1(8))
printf("%f\n",fact2(8))
printf("%f\n",factorial(8))