Skip to content

Instantly share code, notes, and snippets.

@komasaru

komasaru/fibonacci.f95

Last active Nov 22, 2018
Embed
What would you like to do?
Fortran 95 source code to compute the Fibonacci-series.
!****************************************************
! フィボナッチ数列計算
!
! date name version
! 2018.08.20 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2018 mk-mode.com All Rights Reserved.
!****************************************************
!
program fibonacci_main
implicit none
print *, fibonacci(0, 1, 20)
stop
contains
! フィボナッチ数列の計算
! * 初項 f1, f2, 長さ n のフィボナッチ数列を返す
!
! :param(in) integer f1
! :param(in) integer f2
! :param(in) integer n
! :return integer fibonacci(1:n)
recursive function fibonacci(f1, f2, n)
implicit none
integer, intent(in) :: f1, f2, n
integer :: fibonacci(1:n)
integer :: i
fibonacci(1) = f1
fibonacci(2) = f2
do i = 3, n
fibonacci(i) = fibonacci(i - 1) + fibonacci(i - 2)
end do
end function fibonacci
end program fibonacci_main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.