#include
#include
using std::cin;
using std::cout;
using std::vector;
/* #03 from PPP2-8: Create a vector of Fibonacci numbers and print them using the
function from exercise 2. To create the vector, write a function, fibonacci(x,y,v,n),
where integers x and y are ints, v is an empty vector, and n is the number of
elements to put into v; v[0] will be x and v[1] will be y. A Fibonacci number is one
that is part of a sequence where each element is the sum of the two previous ones.
For example, starting with 1 and 2, we get 1, 2, 3, 5, 8, 13, 21, . . . .
Your fibonacci() function should make such a sequence starting with its x and y
arguments.*/
void fibonacci(int x, int y, vector& v, unsigned n) {
v.push_back(x);
v.push_back(y);
for (unsigned i = 2; i < n; ++i) {
v.push_back(v[i - 1] + v[i - 2]);
}
}
int main() {
int x{ 0 }, y{ 0 }, n{ 0 };
vector v;
cout << "Enter two starting values for you fib sequence, and how many you want: ";
while (cin >> x >> y >> n) {
fibonacci(x, y, v, n);
cout << "\nHere's your sequence: ";
for (int i : v) cout << i << " ";
cout << "Enter two starting values for you fib sequence, and how many you want: ";
v.clear();
}
}