logo CodeStepByStep logo


Language/Type: PHP recursion recursion mystery

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

function recursion_mystery5($x, $y) {
    if ($y <= 0) {
        print("0 ");
    } elseif ($x > $y) {
        print("$x ");
        recursion_mystery5($x - $y, $y);
    } else {
        recursion_mystery5($x, $y - $x);
        print("$y ");
recursion_mystery5(6, 3);
recursion_mystery5(2, 3);
recursion_mystery5(5, 8);
recursion_mystery5(21, 12);
recursion_mystery5(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.