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


 
0 => int total;
fun int factorial(int i)
{
    if (i == 0) return 1;
    else
    {
        i * factorial(i - 1) => total;
    } 
    return total;
}
 
// == another way 
fun int factorial(int x)
{ 
    if (x <= 1 ) return 1; 
    else return x * factorial (x - 1);
}
 
// call
factorial (5) => int answer;
 
// test
if ( answer == 120 ) <<<"success">>>;
 