Created
November 5, 2014 21:24
-
-
Save Buzz-Lightyear/540d0fe66e966141a5b5 to your computer and use it in GitHub Desktop.
Project Euler Problem 2 - Sum of Even Fibonacci numbers below 4 million
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
#include <iostream> | |
#include "stdint.h" | |
using namespace std; | |
int main() { | |
uint64_t sumOfEvenValues = 2; | |
for(uint64_t a = 1, b = 2, term = 0;;) | |
{ | |
term = a + b; | |
a = b; | |
b = term; | |
term = a + b; | |
a = b; | |
b = term; | |
if(term <= 4000000LL) | |
{ | |
term = a + b; | |
sumOfEvenValues += term; | |
a = b; | |
b = term; | |
} | |
else | |
break; | |
} | |
cout << sumOfEvenValues << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment