Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active December 8, 2021 01:05
Show Gist options
  • Save komasaru/a97bf5a7aa9fef1f7767db919b3f040d to your computer and use it in GitHub Desktop.
Save komasaru/a97bf5a7aa9fef1f7767db919b3f040d to your computer and use it in GitHub Desktop.
Fortran 95 source code to compute the Fibonacci-series.(Ver.2)
!****************************************************
! フィボナッチ数列計算
!
! DATE AUTHOR VERSION
! 2018.08.20 mk-mode.com 1.00 新規作成
! 2021.12.08 mk-mode.com 1.01 recursive を削除
!
! Copyright(C) 2018-2021 mk-mode.com All Rights Reserved.
!****************************************************
!
program fibonacci_main
implicit none
! インタフェースブロックには引数と関数の戻り値の情報を記述する。
interface
function fibonacci(f1, f2, n)
integer :: f1, f2, n
integer :: fibonacci(1:n) ! 戻り値は長さ n の整数配列
end function fibonacci
end interface
print *, fibonacci(0, 1, 20)
stop
end program fibonacci_main
! フィボナッチ数列の計算
! * 初項 f1, f2, 長さ n のフィボナッチ数列を返す
!
! :param(in) integer f1
! :param(in) integer f2
! :param(in) integer n
! :return integer fibonacci(1:n)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment