logo CodeStepByStep logo

recursion_mystery9

Language/Type: PHP recursion recursion mystery

For each call to the following recursive function, write the output that is produced as it would appear on the console.

function recursion_mystery9($x, $y) {
    if ($x < 0) {
        return -recursion_mystery9(-$x, $y);
    } elseif ($y < 0) {
        return -recursion_mystery9($x, -$y);
    } elseif ($x == 0 && $y == 0) {
        return 0;
    } else {
        $x2 = intval($x / 10);
        $y2 = intval($y / 10);
        return 100 * recursion_mystery9($x2, $y2) + 10 * ($x % 10) + $y % 10;
    }
}
recursion_mystery9(12, 49);
recursion_mystery9(73, -8);
recursion_mystery9(-248, -3795);

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.