logo CodeStepByStep logo

recursionMystery10

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.

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

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.