GATE CS 2025 Set 2 | Question 33
Programming & Data Structures › Basics & Control Structures · NAT · 1 mark · Answer: 21
- Question 33Programming & Data Structuresnat1 markConsider the C code:
The output of the given C code segment is ________. (Answer in integer)int x=126, y=105; do { if(x>y) x=x-y; else y=y-x; } while(x!=y); printf("%d", x);Answer: 21
Solution
Answer: 21 This is Euclid's subtraction method, which computes :
, so it prints .126,105 -> 21,105 -> 21,84 -> 21,63 -> 21,42 -> 21,21 (stop)
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 →