Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class fib{
- public:
- int count = 0, m;
- int f(int n){
- if(n == 0){
- return 0;
- } else if(n == 1){
- return 1;
- } else{
- count += 2;
- return f(n-1)+f(n-2);
- }
- }
- };
- int main() {
- int t;
- cin >> t;
- while(t--){
- int n, k;
- cin >> n;
- fib j;
- k = j.f(n);
- cout << "fib(" << n << ") = " << j.count << " calls = " << k << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement