Skip to content

Instantly share code, notes, and snippets.

@NerdyNerves
Last active August 29, 2015 14:01
Show Gist options
  • Save NerdyNerves/344531385423732fd2b0 to your computer and use it in GitHub Desktop.
Save NerdyNerves/344531385423732fd2b0 to your computer and use it in GitHub Desktop.
Project Euler, Fibonacci Sequence Solution
#include <iostream>
using namespace std;
int main()
{
int a, // holds first term
b, // holds second term
c, // holds third term
sum; // holds sum
const int SIZE = 4000000;
// Initialize first two Fibonacci terms
a = 1;
b = 2;
// Initialize sum
sum = 0;
do {
if (b%2 == 0) {
sum+=b;
}
c = a + b;
a = b + c;
b = c + a;
} while (c <= SIZE);
cout << sum << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment