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?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.