GATE CS 2025 Set 2 | Question 33

Programming & Data Structures › Basics & Control Structures · NAT · 1 mark · Answer: 21

  1. Question 33Programming & Data Structuresnat1 mark
    Consider the C code:
    int x=126, y=105;
    do {
        if(x>y) x=x-y;
        else    y=y-x;
    } while(x!=y);
    printf("%d", x);
    The output of the given C code segment is ________. (Answer in integer)

    Answer: 21

    Solution

    Answer: 21 This is Euclid's subtraction method, which computes :
    126,105 -> 21,105 -> 21,84 -> 21,63 -> 21,42 -> 21,21  (stop)
    , so it prints .

More GATE PYQ on Basics & Control Structures

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2025 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →