Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Trace the following program using storage layout for each recursive call and sho

ID: 3777076 • Letter: T

Question

Trace the following program using storage layout for each recursive call and show the output. Use 5 as input data.

//File : recure6.cpp

//Purpose: To show some recursive examples.

#include <iostream.h>

#include <conio.h>

#include <iomanip.h>

void counting1(int);

void counting2(int);

void counting3(int);

void main()

{

int temp;

cout << "Enter a value for counting "; Enter 5

cin >> temp;

counting1(temp); // function call

cout << endl;

counting2(temp); // function call

cout << endl;

counting3(temp); // function call

}

void counting1(int n)

{ // Assume n is 5 to start with

if (n > 0)

{

cout << setw(5) << n;

counting1(n - 1);

cout << setw(5) << n;

}

else

cout << setw(5) << n;

}

void counting2(int m) // Assume m is 5 to start with

{

if (m >= 0)

{

cout << setw(5) << m;

counting2(m - 1);

};

}

void counting3(int p) // Assume p is 5 to start with

{

if (p >= 0)

{

counting3(p - 1);

cout << setw(5) << p;

};

}

Explanation / Answer

Let us go Step by Step

    5    4    3    2    1    0    1    2    3    4    5
    5    4    3    2    1    0
    0    1    2    3    4    5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote