logo CodeStepByStep logo

recursion_mystery3

Language/Type: PHP recursion recursion mystery

For each of the calls to the following recursive function below, indicate what output is produced:

function recursion_mystery3($n) {
    if ($n < 0) {
        return -recursion_mystery3(-$n);
    } elseif ($n < 10) {
        return ($n + 1) % 10;
    } else {
        return 100 * recursion_mystery3(intval($n / 10)) + ($n + 1) % 10;
    }
}
recursion_mystery3(7)
recursion_mystery3(42)
recursion_mystery3(385)
recursion_mystery3(-790)
recursion_mystery3(89294)

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.