The following example calculates the factorial of a number and uses n! = n(n-1)!
PROGRAM Mayne
IMPLICIT NONE
PRINT*, fact(12) ! etc
CONTAINS
RECURSIVE FUNCTION fact(N) RESULT(N_Fact)
INTEGER, INTENT(IN) :: N
INTEGER :: N_Fact ! also defines type of fact
IF (N > 0) THEN
N_Fact = N * fact(N-1)
ELSE
N_Fact = 1
END IF
END function FACT
END PROGRAM Mayne
To calculate 4!,
For more information, click here