!Input: a non-negative integer n  
!Output: n factorial, computed recursively

program factorial
    implicit none
    integer :: n, result

    ! Read the number from the standard input
    read *, n

    ! Compute the factorial
    result = fact(n)

    ! Print the result
    write(*, '(I0)') result

contains

    recursive function fact(n) result(res)
        integer, intent(in) :: n
        integer :: res

        if (n == 0) then
            res = 1
        else
            res = n * fact(n - 1)
        end if
    end function fact

end program factorial