Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions chapter08/ex04_approx_int.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <vector>
#include <stdexcept>
using namespace std;

// pass by const reference
void print(string label, const vector<int>& v){
cout << label << endl;
for(int x: v){
cout << x << " ";
}
cout << endl;

}

// keep generating integers until we have an overflow
int fibonacci(int x, int y, vector<int>& v){
v.push_back(x);
v.push_back(y);
while(y > x){
int z = x + y;
v.push_back(z);
x = y;
y = z;
}
return x;
}

int main(){
vector<int> v;
cout << fibonacci(1, 2, v);
}