Skip to content

Instantly share code, notes, and snippets.

@NerdyNerves
Last active August 29, 2015 14:02
Show Gist options
  • Save NerdyNerves/befa71df78c8c2aa6dff to your computer and use it in GitHub Desktop.
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.
#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;
}
@ankur20us
Copy link

What is the question and what you posted?facepalm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment