allia

рекурсивный фибоначчи

Sep 14th, 2020
825
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. long long fib ( int a, int n, long long f, long long l)
  6. {
  7.   l+=f;
  8.   f=l-f;
  9.   n++;
  10.   if (n==a-1)
  11.   return f;
  12.   else return fib (a, n, f, l);
  13. }
  14. int main()
  15. {
  16.   int a=0, n=0, l=1, f=0;
  17.   cin >> a;
  18.   if (a==1)
  19.     cout << 0;
  20.      else if (a==2)
  21.       cout << 1;
  22.       else cout << fib (a, n, f, l);
  23. }
RAW Paste Data