2,910 views

Assume $A$ and $B$ are non-zero positive integers. The following code segment:

while(A!=B){
if*(A> B)
A -= B;
else
B -= A;
}
cout<<A; // printing the value of A
1. Computes the $LCM$ of two numbers
2. Divides the larger number by the smaller number
3. Computes the $GCD$ of two numbers
4. Finds the smaller of two numbers

it computes the GCD of two numbers so, option C is correct.

What is the significance of "*" after if statement?

@Sayan Bose

Can you explain significance of "*"?

Typing mistake

### Subscribe to GO Classes for GATE CSE 2022

This is Euclidean algo for determining HCF of two numbers which works in this way :

If we subtract smaller number from larger (we reduce larger number), GCD doesn’t change. So if we keep subtracting repeatedly the larger of two, we end up with GCD.
by
34 51 77

### 1 comment

it can be solved, by taking suitable numbers, such that each option gets a unique answer.

eg: A = 8, B = 12

option A) gives LCM of two numbers = 24

option B) if you divide a larger number by a smaller number it gives = 1

option C) GCD of two numbers = 4

option D) smaller of two numbers  = 8

now if you run the code by taking A = 8 and B=12, it gives the output as 4, which is GCD of two numbers.

option C is correct.
by
3 6 20

1 vote
1
3,465 views