GATE 2002
February 2, 2024NTA UGC NET JUNE 2023 Paper-1
February 2, 2024Programming
Question 13 |
Assume that X and Y are non-zero positive integers. What does the following Pascal program segment do?
while X <>Y do if X > Y then X := X – Y else Y := Y – X; write(X);
Computes the LCM of two numbers | |
Divides the larger number by the smaller number | |
Computes the GCD of two numbers | |
None of the above |
Question 13 Explanation:
Let X=3 and Y=5
1st pass : X=3 and Y=2
2nd pass : X=1 and Y=2
3rd pass : X=1 and Y=1
Write(X), which writes 1. Which is nothing but GCD of 3 & 5.
1st pass : X=3 and Y=2
2nd pass : X=1 and Y=2
3rd pass : X=1 and Y=1
Write(X), which writes 1. Which is nothing but GCD of 3 & 5.
Correct Answer: C
Question 13 Explanation:
Let X=3 and Y=5
1st pass : X=3 and Y=2
2nd pass : X=1 and Y=2
3rd pass : X=1 and Y=1
Write(X), which writes 1. Which is nothing but GCD of 3 & 5.
1st pass : X=3 and Y=2
2nd pass : X=1 and Y=2
3rd pass : X=1 and Y=1
Write(X), which writes 1. Which is nothing but GCD of 3 & 5.