GCD of Two Numbers in C++

Hello Everyone, I am in learning face to c++ and I am confused in gcd of the 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 source. Check the code and Please suggest me, Is it right or not?

int GCD(int A, int B) {
    int m = min(A, B), gcd;
    for(int i = m; i > 0; --i)
        if(A % i == 0 && B % i == 0) {
            gcd = i;
            return gcd;

Your code is absolutely correct
And here’s a bit more optimized approach :
int GCD(int a, int b){
return b==0 ? a : GCD(b,a%b);