logo CodeStepByStep logo

recursionMystery1X

Language/Type: C++ recursion
Author: Marty Stepp (on 2016/10/26)

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

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.