Advertisement
pgiovanni

Untitled

Jul 26th, 2021
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int fibonacci (int requested, vector<int> fsequence) {
  8.  
  9.    
  10.     int next;
  11.    
  12.  
  13.  
  14.     for (int i = 2; i < requested; i++){
  15.  
  16.    
  17.         next = fsequence[i-1]  + fsequence[i-2];
  18.  
  19.  
  20.         fsequence.push_back(next);
  21.  
  22.            
  23.     }
  24.  
  25.  
  26.     return fsequence[requested - 1];
  27.  
  28.  
  29.  
  30. }
  31.  
  32.  
  33. int main () {
  34.  
  35.    vector<int> fsequence;
  36.  
  37.    fsequence.push_back(0);
  38.  
  39.    fsequence.push_back(1);
  40.  
  41.     for (int rq = 0; rq <= 100; rq++)
  42.  
  43.  
  44.     cout << fibonacci(rq, fsequence) << endl;
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement