SHARE
TWEET

Simple recursive fibonacci function in Fortran

a guest Oct 10th, 2011 161 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program fib
  2.   implicit none
  3.   integer :: i
  4.   i = fibonacci(40)
  5. contains
  6.   recursive function fibonacci(n) result(fib)
  7.     integer :: n
  8.     integer :: fib
  9.  
  10.     if (n < 2) then
  11.       fib = 1
  12.     else
  13.       fib = fibonacci(n-2) + fibonacci(n-1)
  14.     endif
  15.   end function fibonacci
  16. end program fib
  17.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top