logo CodeStepByStep logo

recursionMysteryPrintDigits

Language/Type: C++ recursion

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

void recursionMysteryPrintDigits(int x) {
    if (x < 10) {
        cout << x;
    } else {
        int y = x % 10;
        cout << y;
        recursionMysteryPrintDigits(x / 10);
        cout << y;
    }
}
recursionMysteryPrintDigits(7);
recursionMysteryPrintDigits(38);
recursionMysteryPrintDigits(194);
recursionMysteryPrintDigits(782);
recursionMysteryPrintDigits(3842);

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.