PROGRAM Factorial
     
IMPLICIT NONE
   INTEGER :: fact 
   Integer :: num

   Print *, 'Enter the value:'
   Read *, num
   PRINT *, num,'! =', fact(num) 
    
 END PROGRAM Factorial
     
RECURSIVE FUNCTION fact(N) RESULT (N_Fact)

INTEGER, INTENT(IN)  :: N
	  
IF (N > 0) THEN
  N_Fact = N * fact(N-1)
ELSE
  N_Fact = 1
END IF
     
END function FACT
     

