I solving the problems at Project Euler
I'm at problem 2
and I have made this program so far
but I dont know why it takes too much time to give me the answer
even if the fibonacci number is 4
the code is this
any hint on how to improve would be really appreciatedCode:#include <iostream>
using namespace std;
int main ()
{
typedef unsigned long ul;
ul n1 = 0;
ul n2 = 1;
ul n3;
ul index1 = 0;
long double sum = 0;
while (index1 < 4) {
n3 = n1 + n2;
if ( n3 % 2 == 0 ) { sum += n3; }
n1 = n2;
n2 = n3;
}
cout << sum;
return EXIT_SUCCESS;
}
thanks