Last active
August 29, 2015 14:02
-
-
Save NerdyNerves/befa71df78c8c2aa6dff to your computer and use it in GitHub Desktop.
Project Euler #7, C++. Determines 10001st prime and also prints how long it took to calculate.
This file contains 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 <ctime> | |
using namespace std; | |
int main() | |
{ | |
clock_t t; | |
t = clock(); | |
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 (b <= SIZE); | |
cout << "The sum of all Fibonacci sequence values that are less than 400000 and even is: " << sum << endl; | |
t = clock() - t; | |
printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the question and what you posted?facepalm