logo CodeStepByStep logo

RecursionMystery1

Language/Type: C# recursion

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

public static void RecursionMystery1(int x, int y)
{
    if (y <= 0)
    {
        Console.Write("0 ");
    }
    else if (x > y)
    {
        Console.Write(x + " ");
        RecursionMystery1(x - y, y);
    }
    else
    {
        RecursionMystery1(x, y - x);
        Console.Write(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.