logo CodeStepByStep logo

recursionMystery10

Language/Type: C++ recursion
Author: Marty Stepp (on 2016/08/27)

For each call to the following recursive function, write the output that is produced as it would appear on the console.

void recursionMystery10(int x) {
    cout << x << " ";
    if (x <= 1) {
        cout << "END ";
    } else if (x % 2 == 0) {
        recursionMystery10(x / 2);
        cout << "+ ";
    } else {
        cout << "[ ";
        recursionMystery10(3 * x + 1);
        cout << "] ";
    }
}
recursionMystery10(1);
recursionMystery10(4);
recursionMystery10(3);

You must log in before you can solve this problem.


Log In

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.