Skip to content

Instantly share code, notes, and snippets.

@madebyjeffrey
Created March 6, 2011 07:22
Show Gist options
  • Save madebyjeffrey/857104 to your computer and use it in GitHub Desktop.
Save madebyjeffrey/857104 to your computer and use it in GitHub Desktop.
program euler002
implicit none
integer :: i = 0
integer :: f = 0
integer :: s = 0
do
i = i + 1
f = fib(i)
if (f >= 4e6) then
exit
else if (mod(f,2)==0) then
s = s + f
end if
end do
print *, 'Fibs: ', s
contains
recursive function fib(n) result (r)
integer n, r
if (n < 1) then
r = 0
else if (n < 3) then
r = 1
else
r = fib(n-1) + fib(n-2)
end if
return
end function fib
end program euler002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment