Soham_K

Is this Fib recursion?

Mar 27th, 2021 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n;
  5. void fib(int y, int x, int cnt)
  6. {
  7.     if(cnt == n)
  8.         return;
  9.     cout << x << " ";
  10.     cnt++;
  11.     int t = x;
  12.     x = y;
  13.     y = t + y;
  14.     fib(y, x, cnt);
  15.     return;
  16. }
  17.  
  18. int main() {
  19.     cin >> n;
  20.     fib(1, 0, 0);
  21.     return 0;
  22. }
  23.  
Add Comment
Please, Sign In to add comment