Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Hello, please find the requested code below

+5 votes
asked Jan 23 by marc (290 points)

    PROGRAM Faculteit

  2     Implicit None

  3     Integer ::  N,Result

  4     Result=0

  5     N=4

  6     Call Factorial(N,Result)

  7 

  8 100 Print*,'  N:',N,' Facorial:',Result

  9 

 10     END PROGRAM

 11 

 12 

 13 

 14 !

 15 !=================================================================

 16     RECURSIVE SUBROUTINE Factorial(N, Result)

 17      IMPLICIT NONE

 18      INTEGER, INTENT(IN)    :: N

 19      INTEGER, INTENT(INOUT) :: Result

 20      IF (N > 0) THEN

 21       CALL Factorial(N-1,Result)

 22       Result = Result * N

 23      ELSE

 24       Result = 1

 25     END IF

 26    END SUBROUTINE Factorial

 27 !=================================================================

related to an answer for: Fortran program

1 Answer

0 votes
answered Jan 27 by Peter Minarik (86,240 points)

If I just copy the code into the OnlineGDB compiler (and get rid of the line numbers!!!), then your code runs and even returns the correct value.

Maybe you have multiple files in your project? Check the tabs above the code editor pane.

I'd suggest just creating a new (clean) project and migrating your files over there.

PROGRAM Faculteit
    Implicit None
    Integer ::  N,Result
    Result=0
    N=4
    Call Factorial(N,Result)

100 Print*,'  N:',N,' Facorial:',Result

END PROGRAM

!
!=================================================================
    RECURSIVE SUBROUTINE Factorial(N, Result)
     IMPLICIT NONE
     INTEGER, INTENT(IN)    :: N
     INTEGER, INTENT(INOUT) :: Result
     IF (N > 0) THEN
      CALL Factorial(N-1,Result)
      Result = Result * N
     ELSE
      Result = 1
    END IF
   END SUBROUTINE Factorial
!=================================================================
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...