Logo

Programming-Idioms

History of Idiom 31 > diff from v51 to v52

Edit summary for version 52 by tkoenig:
New Fortran implementation by user [tkoenig]

Version 51

2019-09-26, 15:02:19

Version 52

2019-09-26, 19:25:06

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
module x
  implicit none
contains
  recursive function fac (n) result (res)
    integer, intent(in) :: n
    integer :: res
    if (n <= 0) then
       res = 1
    else
       res = fac(n-1) * n
    end if
  end function fac
end module x