logo CodeStepByStep logo

recursion_mystery14

Language/Type: PHP recursion recursion mystery

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

function recursion_mystery14($n) {
    if ($n < 0) {
        return recursion_mystery14(-$n);
    } elseif ($n < 10) {
        return $n;
    } else {
        return $n % 10 + recursion_mystery14(intval($n / 10));
    }
}
recursion_mystery14(8)
recursion_mystery14(74)
recursion_mystery14(-513)
recursion_mystery14(3052)
recursion_mystery14(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.