Question: The objective of this assignment is to examine the runtime speed of recursive programs. You are to write 3 C++ recursive programs: factorial, fibonacii, and

The objective of this assignment is to examine the runtime speed of recursive programs. You are to "write" 3 C++ recursive programs: factorial, fibonacii, and hanoi For Fibonacci, determine the number of times FIB is called to compute:

Fib(10)

Fib(20)

Fib(30)

Do the same for Factorial and Hanoi.

Fact (10), Hanoi with 10 rings

Fact (20), Hanoi with 20 rings

Fact (30), Hanoi with 30 rings

In the D2L drop box, place a Word file that contains

A 3X3 table with labels:

Hanoi Factorial Fibonacci
10
20
30

the complete code for Hanoi (includes the increment and output statements)

the complete code for Factorial

the complete code for Fibonacci

Here's some of the fibonacci code i was working on

#include

#include

using namespace std;

int fib(int); // fibonacci function

int main()

{

int number; // Value to compute fib for

cout << "Enter a number => ";

cin >> number;

cout << " Answer is: " << fib(number) << endl;

return 0;

}

int fib(int num)

{

//cout << "Fibonacci called with: " << num << endl;

if (num <0)

{

cout << " error Invalid number ";

exit(1);

}

else if (num == 0)

return 0;

else if (num == 1)

return 1;

else

return (fib(num - 1) + fib(num - 2));

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!