Open In App

GATE | GATE-CS-2004 | Question 41

Like Article
Like
Save
Share
Report

Consider the following C program




main()
{
    int x, y, m, n;
    scanf ("%d %d", &x, &y);
    /* Assume x > 0 and y > 0  */
    m = x;
    n = y;
    while (m! = n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    print f ("% d", n);
}


The program computes

(A) x ÷ y using repeated subtraction
(B) x mod y using repeated subtraction
(C) the greatest common divisor of x and y
(D) the least common multiple of x and y


Answer: (C)

Explanation: The given program is iterative implementation of Euclid’s Algorithm for GCD

Quiz of this Question


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads