Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For each case, we want to plot input (n x-axis) verses execution time (t y-axis). Each of the above cases has two programs to solve

For each case, we want to plot input (n x-axis) verses execution time (t y-axis). Each of the above cases has two programs to solve the corresponding problem. We want to compare the behavior of both programs (i.e. practical comparison) by prepare a figure using Excel. Each figure should have two lines, one for the first program and the other for the second program. In addition to the figures, provide the collected data in separated tables.

Case 2: Factorial

Case 2: Compute the factorial of an integer. The factorial of an integer can be found using an iterative program or a recursive program.

Program 1 (iterative)

Program 2 (recursive)

#include

using namespace std;

main()

{

int n,i,fact = 1;

cout<<"input n: ";

cin>>n;

for(i=1;i<=n;i++)

fact=fact*i;

cout<

}

#include

using namespace std;

int fact(int n)

{

if (n==0)

return 1;

else

return n*fact(n-1);

}

main()

{

int n;

cout<<"input n: ";

cin>>n;

cout<

}

Case 2: Compute the factorial of an integer. The factorial of an integer can be found using an iterative program or a recursive program.

Program 1 (iterative)

Program 2 (recursive)

#include

using namespace std;

main()

{

int n,i,fact = 1;

cout<<"input n: ";

cin>>n;

for(i=1;i<=n;i++)

fact=fact*i;

cout<

}

#include

using namespace std;

int fact(int n)

{

if (n==0)

return 1;

else

return n*fact(n-1);

}

main()

{

int n;

cout<<"input n: ";

cin>>n;

cout<

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions