Last active
August 29, 2015 14:05
-
-
Save dgodfrey206/750340fbd89ae48583f3 to your computer and use it in GitHub Desktop.
Project Euler #2
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
// Answer: 4,613,732 | |
unsigned int fib(unsigned int n) { | |
return n <= 1 ? n : fib(n-1) + fib(n-2); | |
} | |
int main() | |
{ | |
unsigned int sum(0); | |
for (unsigned int i(2), r(1); r <= 4000000; r = fib(++i)) | |
if (r % 2 == 0) sum += r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment