You are on page 1of 1

!

MS$FREEFORM
program fattoriale
implicit none
integer :: N
real*8 :: fatt
write(*,*) 'Calcolo del fattoriale di N'
write(*,*) 'Inserisci il valore di N (>0) : '
read(*,*) N
write(*,*) 'Fattoriale real = ',fatt(n)
end program fattoriale
function fatt(n)
implicit none
integer, intent(in) :: n
integer :: i
real*8 :: fatt, prod
!
if (n .eq. 0) then
fatt = 1.D0
return
else if (n .gt. 0) then
prod = 1.D0
do i=1,N
prod = prod * i
end do
!
fatt = prod
return
end if
end function fatt

You might also like