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, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
#include <iostream>
using namespace std;
int main() {
int i =1;
int j =2;
int k = 0;
while (k<4000000)
{
k = i +j;
i = k+j;
j=i +k;
}
cout << i <<endl;
cout << j << endl;
cout << k << endl;
return 0;
}
Am I even doing this correctly? Why am I getting three different nu
Aucun commentaire:
Enregistrer un commentaire