fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. void imprime(vector<int>& v) {
  6. for(int x = 0; x < v.size(); x++) cout << v[x] << " ";
  7. }
  8.  
  9. void fibonacci(int x, int y, vector<int>& fi) {
  10. int z = 0;
  11. for (int b = 0; b < fi.size(); b++) {
  12. z = x + y;
  13. fi[b] = z;
  14. x = y;
  15. y = z;
  16. }
  17. }
  18.  
  19. int main() {
  20. int valor1, valor2, numeroElementos;
  21. while (cin >> valor1 >> valor2 >> numeroElementos) {
  22. vector<int> numeros(numeroElementos);
  23. fibonacci(valor1, valor2, numeros);
  24. imprime(numeros);
  25. }
  26. }
  27.  
  28. //https://pt.stackoverflow.com/q/126405/101
Success #stdin #stdout 0s 4536KB
stdin
0
1
8
stdout
1 2 3 5 8 13 21 34