Problem

( Fibonacci series) Modify Listing, ComputeFibonacci.cpp, so that the program finds the nu...

( 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 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT