
PROGRAM Fattoriale
!————————————————————————-
! Calcolo del fattoriale di un numero intero.
!————————————————————————-
IMPLICIT NONE
INTEGER:: N
WRITE(*,*) “Digitare un numero intero non negativo”
READ(*,*) N
WRITE(*,*) “Il fattoriale del numero e’:”, Fatt(N)
STOP
CONTAINS
!————————————————————————-
RECURSIVE FUNCTION Fatt(N) RESULT(N_fatt)
!————————————————————————-
INTEGER,INTENT(IN):: N
INTEGER :: N_fatt
SELECT CASE (N)
CASE (:-1)
STOP ‘ERRORE: Funzione Fatt, argomento negativo’
CASE (0)
N_fatt = 1
CASE (1:)
N_fatt = N*Fatt(N-1)
END SELECT
RETURN
END FUNCTION Fatt
END PROGRAM Fattoriale
Giuseppe Ciaburro









Anteprima del commento