I have been trying to do this Fibonacci sequence with the default args for awhile. I keep coming up with incorrect results. The total should be 4613732. and as it goes up, the 4 should be a five, and the 7 should be an eight, etc.
#include <iostream>
#include <vector>
usingnamespace std;
vector<int> fib(int a=1, int b=2, int max=4000000){
vector<int> v;
long sum;
v.push_back(a);
v.push_back(b);
while (a < max){
sum = 0;
sum = b + a;
b = a;
a = sum;
v.push_back(sum);
}
return v;
}
int main(){
int total = 0;
vector<int> v;
v = fib();
for (int i=0; i<v.size(); i++){
cout << v[i] << endl;
total += v[i];
}
cout << "total: " << total << endl;
1) a = 1; v.push_back( a );
2) b = 2; v.push_back( b )
3) sum = 3; v.push_back( sum ); b = a ( b == 1 ); a = sum; ( a == 3 );
4). sum = 4 ( b (== 1 ) + a ( == 3 ) ); ....