logo CodeStepByStep logo

recursionMystery1

Language/Type: C++ recursion

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

void recursionMystery1(int x, int y) {
    if (y <= 0) {
        cout << "0 ";
    } else if (x > y) {
        cout << x << " ";
        recursionMystery1(x - y, y);
    } else {
        recursionMystery1(x, y - x);
        cout << y << " ";
    }
}
recursionMystery1(6, 3);
recursionMystery1(2, 3);
recursionMystery1(5, 8);
recursionMystery1(21, 12);
recursionMystery1(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.