logo CodeStepByStep logo

recursion_mystery4

Language/Type: PHP recursion recursion mystery

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

function recursion_mystery4($n) {
    if ($n <= 1) {
        print("*");
    } elseif ($n == 2) {
        recursion_mystery4($n - 1);
        print("*");
    } else {
        print("(");
        recursion_mystery4($n - 2);
        print(")");
    }
}
recursion_mystery4(2);
recursion_mystery4(3);
recursion_mystery4(4);
recursion_mystery4(6);
recursion_mystery4(9);

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.