Friday, July 3, 2009

Greatest Common Divisor (Recursion)

Here's a sample solution to solve the GCD recursively.

public long GCD(long numberA, long numberB) {
if (numberB==0)
return numberA;
else
return GCD(numberB, numberA % numberB);
}
Update: The code is also available in Python in this entry

0 comments:

Post a Comment