diff --git a/chapter08/ex04_approx_int.cpp b/chapter08/ex04_approx_int.cpp new file mode 100644 index 0000000..b121e1a --- /dev/null +++ b/chapter08/ex04_approx_int.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +using namespace std; + +// pass by const reference +void print(string label, const vector& 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& 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 v; + cout << fibonacci(1, 2, v); +}