logo CodeStepByStep logo

RecursionMysteryDivMod

Language/Type: C# recursion

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

public static 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 method 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.