Anik_Akash

fibo_series_recursiv

Nov 21st, 2020 (edited)
759
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //#include<bits/stdc++.h>
  2. #include<cstdio>
  3. #include<sstream>
  4. #include<cstdlib>
  5. #include<cctype>
  6. #include<cmath>
  7. #include<algorithm>
  8. #include<set>
  9. #include<queue>
  10. #include<stack>
  11. #include<list>
  12. #include<iostream>
  13. #include<fstream>
  14. #include<numeric>
  15. #include<string>
  16. #include<vector>
  17. #include<cstring>
  18. #include<map>
  19. #include<iterator>
  20. #define pi           (acos(-1.0)) //3.1415926535897932384626
  21. #define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
  22. #define fasterio     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  23. #define NL           printf("\n")
  24. #define fin          freopen("int.txt","r",stdin);
  25. #define fout         freopen("out.txt","w",stdout);
  26.  
  27. using namespace             std;
  28. typedef long long int       ll;
  29. typedef double              dl;
  30. typedef unsigned long long  ul;
  31.  
  32. // ----------------------Pre made Functions---------------------------//
  33.  
  34. template <class T> T gcd(T a, T b){if(a == 0) return b;return gcd(b%a, a);}
  35. template <class T> T lcm(T a, T b){return ((a*b)/gcd(a, b));}
  36.  
  37.  
  38.  
  39. // ----------------------------Slove----------------------------------//
  40. int arr[20];
  41.  
  42. int fibo(int n)
  43. {
  44.    if(n==0 || n==1) return arr[n]=n;
  45.    else return arr[n]=fibo(n-1)+fibo(n-2);
  46.  
  47.    return arr[n];
  48. }
  49.  
  50. int main()
  51. {
  52.    fin
  53.    fout
  54.    fasterio
  55.  
  56.       int n;
  57.       cin>>n;
  58.       fibo(n);
  59.       for(int i=0; i<=n; i++){
  60.          cout<<arr[i]<<" ";
  61.       }
  62.  
  63.     return 0;
  64. }
  65. //author anikaksh;
  66. //trust me ur the competitor of your own, not ur friend!
  67. //Thanks To My Seniors and frndzz who help me all the time's
  68. //Contest link:
  69.  
RAW Paste Data