logo CodeStepByStep logo

recursion_mystery0

Language/Type: PHP recursion recursion mystery
Author: Melissa Hovik (on 2018/01/05)

Given the function below, what is the output of the following call?

function mystery($n) {
    if ($n < 1) {
        return $n;
    } else {
        $a = intval($n / 10);
        return $n + mystery($a);
    }
}
mystery(12345);
(order shuffled)

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.