Created
November 18, 2015 03:21
-
-
Save rinx/f60d247d6e5fd82e52e3 to your computer and use it in GitHub Desktop.
An example of recursive function on fortran.
This file contains hidden or 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
program main | |
print *, fib(30) | |
contains | |
recursive function fib(n) result(res) | |
integer :: n | |
integer :: res | |
if (n <= 2) then | |
res = 1 | |
else | |
res = fib(n-1) + fib(n-2) | |
endif | |
end function fib | |
end program main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment