Created
March 6, 2011 07:22
-
-
Save madebyjeffrey/857104 to your computer and use it in GitHub Desktop.
This file contains 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 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