Question: C++ Analyze the following two programs: A: int main() { f(5); } void f(int length) { if (length > 1) { cout < < (length

C++

Analyze the following two programs:

A:

int main()

{

f(5);

}

void f(int length)

{

if (length > 1)

{

cout << (length - 1) << " ";

f(length - 1);

}

}

}

B:

int main()

{

f(5);

}

void f(int length)

{

while (length > 1)

{

cout << (length - 1) << " ";

f(length - 1);

}

}

}

which one is correct?

1- Program A produces the output 4 3 2 1 and Program B prints 4 3 2 1 1 1 .... 1 infinitely.

2- The two programs produce the same output 1 2 3 4 5.

3- The two programs produce the same output 4 3 2 1.

4- The two programs produce the same output 5 4 3 2 1.

5/ The two programs produce the same output 1 2 3 4.

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!