Advertisement
Ritam_C

Uri 1029

Dec 29th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class fib{
  5.     public:
  6.         int count = 0, m;
  7.         int f(int n){
  8.             if(n == 0){
  9.                 return 0;
  10.             } else if(n == 1){
  11.                 return 1;
  12.             } else{
  13.                 count += 2;
  14.                 return f(n-1)+f(n-2);
  15.             }
  16.         }  
  17. };
  18.  
  19. int main() {
  20.     int t;
  21.     cin >> t;
  22.    
  23.     while(t--){
  24.         int n, k;
  25.         cin >> n;
  26.         fib j;
  27.         k = j.f(n);
  28.         cout << "fib(" << n << ") = " << j.count << " calls = " << k << "\n";
  29.     }
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement