logo CodeStepByStep logo

recursion_mystery12

Language/Type: PHP recursion recursion mystery

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

function recursion_mystery12($x, $y) {
    if ($y <= 0) {
        print("0 ");
    } elseif ($x > $y) {
        print("$x ");
        recursion_mystery12($x - $y, $y);
    } else {
        recursion_mystery12($x, $y - $x);
        print("$y ");
        if ($y % 3 == 0) {
            recursion_mystery12($x, $y - $x);
        }
    }
}
recursion_mystery12(6, 3)
recursion_mystery12(2, 3)
recursion_mystery12(5, 8)
recursion_mystery12(21, 12)
recursion_mystery12(3, 10)

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.