Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Last active August 29, 2015 14:05
Show Gist options
  • Save dgodfrey206/750340fbd89ae48583f3 to your computer and use it in GitHub Desktop.
Save dgodfrey206/750340fbd89ae48583f3 to your computer and use it in GitHub Desktop.
Project Euler #2
// 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