Download code
From LiteratePrograms
Back to Fibonacci_numbers_(FORTRAN)
Download for Windows: single file, zip
Download for UNIX: single file, zip, tar.gz, tar.bz2
fib.f90
1 C Copyright (c) 2010 the authors listed at the following URL, and/or 2 C the authors of referenced articles or incorporated external code: 3 C http://en.literateprograms.org/Fibonacci_numbers_(FORTRAN)?action=history&offset=20090816134056 4 C 5 C Permission is hereby granted, free of charge, to any person obtaining 6 C a copy of this software and associated documentation files (the 7 C "Software"), to deal in the Software without restriction, including 8 C without limitation the rights to use, copy, modify, merge, publish, 9 C distribute, sublicense, and/or sell copies of the Software, and to 10 C permit persons to whom the Software is furnished to do so, subject to 11 C the following conditions: 12 C 13 C The above copyright notice and this permission notice shall be 14 C included in all copies or substantial portions of the Software. 15 C 16 C THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 C EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 C MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 C IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 C CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 C TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 C SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 C 24 C Retrieved from: http://en.literateprograms.org/Fibonacci_numbers_(FORTRAN)?oldid=16495 25 26 program main 27 implicit none 28 interface 29 function fib(n) 30 integer, intent(in) :: n 31 integer :: fib 32 end function fib 33 end interface 34 35 print *, fib(10) 36 end program main 37 38 recursive function fib (n) result (fnum) 39 integer, intent(in) :: n 40 integer :: fnum 41 if (n<2) then 42 fnum = n 43 else 44 fnum = fib(n-1) + fib(n-2) 45 endif 46 end function fib 47
