logo CodeStepByStep logo

recursionMystery4

Language/Type: C++ recursion
Author: Marty Stepp (on 2016/06/16)

For each of the calls to the following recursive function below, indicate what output is produced:

void recursionMystery4(int n) {
    if (n <= 1) {
        cout << "*";
    } else if (n == 2) {
        recursionMystery4(n - 1);
        cout << "*";
    } else {
        cout << "(";
        recursionMystery4(n - 2);
        cout << ")";
    }
}
recursionMystery4(2);
recursionMystery4(3);
recursionMystery4(4);
recursionMystery4(6);
recursionMystery4(9);

You must log in before you can solve this problem.


Log In

Need help?

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.