Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int counter, call;
- int fibonacci(int n)
- {
- if(n == 0){
- call++;
- return 0;
- }else if(n == 1){
- call++;
- counter++;
- return 1;
- }else{
- call++;
- return fibonacci(n - 1) + fibonacci(n - 2);
- }
- }
- int main()
- {
- int n, x, res;
- cin >> n;
- for (int i = 0; i < n; ++i)
- {
- counter = 0;
- call = 0;
- cin >> x;
- res = fibonacci(x);
- cout << "fib(" << x << ") = " << call << " calls = " << counter << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement