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


' FB 1.05.0 Win64
 
Function Factorial_Iterative(n As Integer) As Integer
  Var result = 1
  For i As Integer = 2 To n
    result *= i
  Next
  Return result
End Function
 
Function Factorial_Recursive(n As Integer) As Integer
  If n = 0 Then Return 1
  Return n * Factorial_Recursive(n - 1)
End Function
 
For i As Integer = 1 To 5
  Print i; " =>"; Factorial_Iterative(i)
Next
 
For i As Integer = 6 To 10
  Print Using "##"; i; 
  Print " =>"; Factorial_Recursive(i)
Next
 
Print
Print "Press any key to quit"
Sleep