recategorized by
4,098 views
1 votes
1 votes

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
recategorized by

2 Answers

Best answer
2 votes
2 votes
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.
selected by
Answer:

Related questions

1 votes
1 votes
1 answer
1
Arjun asked Apr 22, 2018
5,113 views
An array $A$ consists of $n$ integers in locations $A[0], A , \ldots A[n-1]$. It is required to shift the elements of the array cyclically to the left by $k$ places, wher...
5 votes
5 votes
2 answers
2
Arjun asked Apr 22, 2018
4,564 views
Consider the following C code segmentint f(int x) { if(x<1) return 1; else return (if(x-1)+g(x)); } int g(int x) { if(x<2) return 2; else return (if(x-1)+g(x/2)); }Of the...
3 votes
3 votes
1 answer
3
Arjun asked Apr 22, 2018
5,042 views
The following paradigm can be used to find the solution of the problem in minimum time:Given a set of non-negative integer and a value $K$, determine if there is a subset...
4 votes
4 votes
2 answers
4
Arjun asked Apr 22, 2018
3,846 views
Which of the following is application of Breath First Search on the graph?Finding diameter of the graphFinding bipartite graphBoth (a) and (b)None of the above