logo CodeStepByStep logo

recursionMystery1X

Language/Type: C++ recursion

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

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