int gcd(int a, int b){
if(b==0) return a;
return gcd(b,b%a);
}
If I change return gcd(b,b%a) to return gcd(b,a%b) it works. In the examples I am trying both the algorithms work, but when I use this gcd method on online coding problem, return gcd(b,a%b) works but not the other. Can someone throw some light and provide an example where return gcd(b,b%a) fails?