thanks and is this algorithm correct ?
i have to find the solution for this
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not exceed one million.
here's the new code
Code:
#include <iostream>
using namespace std;
int main ()
{
typedef long double ul;
ul n1 = 0;
ul n2 = 1;
unsigned long n3;
ul sum = 0;
for (ul index = 0; index < 1000000; index++) {
n3 = n1 + n2;
if ((n3 % 2) == 0 ) { sum += n3; }
n1 = n2;
n2 = n3;
}
cout << fixed << sum;
return EXIT_SUCCESS;
}