logo CodeStepByStep logo

recursionMysteryDivMod

Language/Type: C++ recursion

For each call to the following recursive function, write the value that would be returned.

int recursionMysteryDivMod(int n) {
    if (n < 0) {
        return recursionMysteryDivMod(-n);
    } else if (n < 10) {
        return n;
    } else {
        return n % 10 + recursionMysteryDivMod(n / 10);
    }
}

(Side note: What is the function really doing?)

recursionMysteryDivMod(8)
recursionMysteryDivMod(74)
recursionMysteryDivMod(-513)
recursionMysteryDivMod(3052)
recursionMysteryDivMod(82534)

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.