When program uses loop inside GCD to compute the answer how to modify it so it becomes a recursive function call inside of the GCD function?
/*If you any query do comment in the comment section else like the solution*/
GCD using iterative approach
int gcd(int A,int B)
{
int temp;
while(B>0)
{
temp=B;
B=A%B;
A=temp;
}
return A;
}
Modify the above code as below to make it recursive
private static int gcd(int A, int B) {
if(A == 0) return B;
if(B == 0) return A;
return gcd(B, A%B);
}
Get Answers For Free
Most questions answered within 1 hours.