Hello All, I am stack in gcd of two numbers problem. The problem statement is two non-negative integers a and b, we have to find their GCD (greatest common divisor),i.e. the largest number which is a divisor of both a and b. It’s commonly denoted by gcd(a,b) Check the code and Please suggest me, Is it right or not? I am using to solve this problem by Euclid’s Algorithm.
Taken this code reference from here - https://www.interviewbit.com/blog/gcd-of-two-numbers/
import java.util.*;
import java.lang.*;
class Interviewbit {
// extended Euclidean Algorithm
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
}