Easy to understand C/C++ solution


#1

int Solution::gcd(int A, int B) {
int k=A>B?B:A;
if(A==0)
return B;
else if(B==0)
return A;

int i,m=0,z;
for(i=1;i<=k;i++)
{
    if((A%i==0)&&(B%i==0))
    {
        z=i;
        if(z>m)
        m=z;
    }
}
return m;

}