shivambhatele
New Coder
Hello All, I am new in c++ programming and 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) I have taken this code reference from this problem post. Check the code and Please suggest me, Is it right or not?
C++:
// Function to return
// gcd of a and b
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}