logo CodeStepByStep logo

recursionMysteryPrintDigits

Language/Type: C++ recursion
Author: Marty Stepp (on 2016/07/03)

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

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.