Instantly share code, notes, and snippets.

komasaru/fibonacci.f95

Last active December 8, 2021 01:03
Show Gist options
• Save komasaru/89e3b2b6cf2ef3ec3251168c018186b1 to your computer and use it in GitHub Desktop.
Fortran 95 source code to compute the Fibonacci-series.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 !**************************************************** ! フィボナッチ数列計算 ! ! DATE AUTHOR VERSION ! 2018.08.20 mk-mode.com 1.00 新規作成 ! 2021.12.07 mk-mode.com 1.01 recursive を削除 ! ! Copyright(C) 2018-2021 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) 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

komasaru commented Dec 8, 2021

Thank you for letting me know.
I don't remember clearly because it was a long time ago.
But certainly "recursive" wasn't needed.
I removed "recursive".