Fattoriale

Calcolo del fattoriale di un numero intero

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

PUBBLICITÀ
PUBBLICITÀ
Le vostre opinioni
Pubblicato il sabato 04 agosto 2007 in: Programmi

Ultimi interventi

Vedi tutti

Inserisci per primo un commento a questo articolo.

PUBBLICITÀ
PUBBLICITÀ
L'email è richiesta ma non verrà mostrata ai visitatori.
Commenta questo articolo

Registrati per riservare il tuo nickname preferito e per caricare il tuo avatar. Se sei già registrato, effettua il login per usare il tuo nickname.

Si No

Anteprima del commento