21_fibonacci.cpp 414 B

123456789101112131415161718192021222324
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. #define COUNT 15
  5. int main()
  6. {
  7. vector<int> F;
  8. F.push_back(1); // F(1) = 1
  9. F.push_back(1); // F(2) = 1
  10. for (int i = 2; i < COUNT; i++)
  11. {
  12. F.push_back(*(F.end() - 1) + *(F.end() - 2)); // F(x) = F(x-1) +
  13. // F(x-2)
  14. }
  15. cout << "Fibonacci numbers are:" << endl;
  16. for (int i = 0; i < F.size(); i++)
  17. cout << F[i] << ' ';
  18. return 0;
  19. }