Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active Jun 23, 2022
Embed
What would you like to do?
Fortran 95 source code to compute the factorial.
!****************************************************
! 階乗計算
!
! date name version
! 2018.08.20 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2018 mk-mode.com All Rights Reserved.
!****************************************************
!
program fact_main
implicit none
integer n
do n = 0, 20
write (*,'(I3,3X,I20)') n, fact(n)
enddo
stop
contains
! 階乗計算
!
! :param integer n
! :return integer fact
integer(kind=8) recursive function fact(n)
implicit none
integer, intent(IN) :: n
integer :: i
fact = 1
do i = 1, n
fact = fact * i
enddo
return
end function fact
end program fact_main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment