30 lines
468 B
Fortran
30 lines
468 B
Fortran
|
program Fibonacci
|
||
|
implicit none
|
||
|
|
||
|
integer :: i
|
||
|
integer, dimension(10) :: fib_nb
|
||
|
|
||
|
fib_nb(1) = 1
|
||
|
fib_nb(2) = 1
|
||
|
|
||
|
do i = 3, 10
|
||
|
fib_nb(i) = fib_nb(i-1) + fib_nb(i-2)
|
||
|
end do
|
||
|
|
||
|
do i = 1, 10
|
||
|
print *, fib_nb(i)
|
||
|
end do
|
||
|
contains
|
||
|
recursive function fib(n) result(fib_)
|
||
|
integer, intent(in) :: n
|
||
|
integer :: fib_
|
||
|
|
||
|
if (n == 1) then
|
||
|
fib_ = 1
|
||
|
else if (n == 1) then
|
||
|
fib_ = 1
|
||
|
else
|
||
|
fib_ = fib(n-1) + fib(n-2)
|
||
|
end if
|
||
|
end function fib
|
||
|
end program Fibonacci
|