...
GATE 2002
February 2, 2024
NTA UGC NET JUNE 2023 Paper-1
February 2, 2024
GATE 2002
February 2, 2024
NTA UGC NET JUNE 2023 Paper-1
February 2, 2024

Programming

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); 
A
Computes the LCM of two numbers
B
Divides the larger number by the smaller number
C
Computes the GCD of two numbers
D
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.
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.

Leave a Reply

Your email address will not be published. Required fields are marked *