Assume that p and q are non-zero positive integers, the following program…
2022
Assume that p and q are non-zero positive integers, the following program segment will perform – while (p != q) { if (p > q) p = p - q; else q = q - p; } printf("%d", p);
- A.
Subtract small number from large number
- B.
Compute GCD of the given numbers
- C.
Compute LCM of the given numbers
- D.
The loop will run infinitely
Attempted by 157 students.
Show answer & explanation
Correct answer: B
The code implements the Euclidean Algorithm via repeated subtraction to calculate the Greatest Common Divisor (GCD) of p and q.