I have a code that finds the gcd of two numbers, I know it works, but dont understand how it is finding the gcd. Can anyone help me?
1 2 3 4 5 6 7
long gcd(long x1,long x2) // finds the greatest common divisor (gcd)
{ // of two long ints x1 and x2
if(x2)
return(gcd(x2,x1%x2));
elsereturn(labs(x1));
}
Well, you see that this is a recursive function?
It might help if you added some cout statements to display the values of x1 and x2 each time it is called.