( Fibonacci series) Modify Listing, ComputeFibonacci.cpp, so that the pro
gram finds the number of times the fib function is called. ( Hint:Use a globa variable and increment it every time the function is called.)
Listing ComputeFibonacci.cpp
#include
using namespace std;
3
4 // The function for finding the Fibonacci number
5 int fib(int);
6
7int main()
8 {
9 // Prompt the user to enter an integer
cout <<< "Enter an index for the Fibonacci number: ”;
int index; 2 cin >> index;
13
14 // Display factorial
15 cout << "Fibonacci number at index” << index <<< ” is ”
16 << fib(index) << endl ;
17
18 return 0;
19 }
20
21 // The function for finding the Fibonacci number
22int fib(int index)
23 {
24if (index == 0) // Base case
25 return 0;
26 else if (index == 1) // Basecase
27return 1;
28 else // Reduction and recursive calls
29 return fib(index- 1) + fib(index - 2);
30 }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.