logo CodeStepByStep logo

recursionMystery8

Language/Type: C++ recursion

For each call to the following recursive function, write the output that is produced as it would appear on the console. Hint: To avoid re-tracing out long chains of calls, it may help you to look at your own notes on call results that you have already previously computed, and re-use those results as applicable.

void recursionMystery8(int n) {
    if (n <= 1) {
        cout << n;
    } else {
        cout << n << " = (";
        recursionMystery8(n / 2 + n % 2);
        cout << ", ";
        recursionMystery8(n / 2);
        cout << ")";
    }
}
recursionMystery8(3);
recursionMystery8(4);
recursionMystery8(6);
recursionMystery8(7);

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.