A simple factorial function. Use only for small values of as no consideration of efficiency has been made.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip), | intent(in) | :: | n | The value for which the factorial function should be calculated. |
The return value, .
recursive function factorial ( n ) result ( fac )
!! A simple factorial function. Use only for small values of \(n\) as
!! no consideration of efficiency has been made.
implicit none
integer(ip), intent(in) :: n
!! The value for which the factorial function should be calculated.
integer(ip) :: fac
!! The return value, \(n!\).
if (n<2) then
fac = 1
else
fac = n*factorial(n-1)
end if
end function factorial