logo CodeStepByStep logo

recursion_mystery10

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_mystery10($x) {
    print("$x ");
    if ($x <= 1) {
        print("END ");
    } elseif ($x % 2 == 0) {
        recursion_mystery10($x / 2);
        print("+ ");
    } else {
        print("[ ");
        recursion_mystery10(3 * $x + 1);
        print("] ");
    }
}
recursion_mystery10(1);
recursion_mystery10(4);
recursion_mystery10(3);

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.