recursive function factorial(n) result (p)
  implicit none
  integer, intent (in) :: n
  integer :: p

  if (n == 0) p = 1
  if (n >  0) p = n * factorial(n-1)

end function factorial


program ask
  implicit none
  interface
     recursive function factorial(n) result (p)
       implicit none
       integer, intent (in) :: n
       integer :: p
     end function factorial
  end interface

  print *, factorial(5)
end program ask
