Skip to content

Instantly share code, notes, and snippets.

@yuchan
Created November 21, 2012 14:59
Show Gist options
  • Save yuchan/4125258 to your computer and use it in GitHub Desktop.
Save yuchan/4125258 to your computer and use it in GitHub Desktop.
project euler problem #2
#include <iostream>
using namespace std;
int fib(int _n){
if(_n <= 0)
return 0;
else if(_n == 1)
return 1;
else if(_n == 2)
return 2;
else
return fib(_n - 1) + fib(_n - 2);
}
int main()
{
int sum = 0;
int f = 0;
int i = 0;
while((f = fib(i)) < 4000000){
if(f % 2 == 0)
sum += f;
i++;
}
cout << "sum=" << sum << endl;
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment