SUBROUTINE factorial(n,nfact) USE const ! Subroutine to compute n! given the value of n ! n! is returned as a double instead of an integer ! to prevent overflow IMPLICIT NONE ! Dummy variable declarations INTEGER,INTENT(IN) :: n REAL(Kind=dp),INTENT(OUT) :: nfact ! LOCAL variable declarations ! A local variable is a variable that a subroutine needs ! in order to complete the task, but is not sent through ! the dummy argument list. The main program doesn't know ! about these (and doesn't need to know about them). INTEGER :: i ! Main loop for computing n! nfact = 1 DO i = 1,n nfact = nfact*i ENDDO RETURN END SUBROUTINE factorial