/** * @file * Sum of the even Fibonacci numbers less than or equal to 4000000. */ #include long fib(const int); int main(void) { long sum = 0; long value; int i; for (i = 1; (value = fib(i)) <= 4000000; i++) { if (value % 2 == 0) { sum += value; } } printf("%ld\n", sum); return 0; } /** * Computes the `n`th Fibonacci number. */ long fib(const int n) { if (n == 1) { return 1; } if (n == 2) { return 2; } return fib(n - 1) + fib(n - 2); }