factorial Function

public recursive function factorial(n) result(fac)

A simple factorial function. Use only for small values of as no consideration of efficiency has been made.

Arguments

Type IntentOptional AttributesName
integer(kind=ip), intent(in) :: n

The value for which the factorial function should be calculated.

Return Value integer(kind=ip)

The return value, .


Called by

proc~~factorial~~CalledByGraph proc~factorial factorial proc~factorial->proc~factorial proc~abmv5_init abmv5_init proc~abmv5_init->proc~factorial interface~abmv5_init abmv5_init interface~abmv5_init->proc~abmv5_init

Contents

Source Code


Source Code

  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