Last active
October 19, 2016 07:38
-
-
Save BedirYilmaz/f084dc3dd24351979dcd2a94798b1bf2 to your computer and use it in GitHub Desktop.
Sum of the even fibonacci numbers that are smaller than 4000000
This file contains hidden or 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
def fib (n) : | |
if (n == 1 or n==2): | |
return 1 | |
return (fib(n-1) + fib(n-2)) | |
limit = 4000000 | |
x = 1 | |
sum = 0 | |
a = 0 | |
while a < limit: | |
a = fib(x) | |
x += 1 | |
if a % 2 == 0 : | |
sum += a | |
print( " sum of the even fibonacci numbers that are smaller than 4000000 is " + str(sum)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment