Pages

Sunday, January 23, 2011

GCD Recursive Method




The greatest common divisor (g.c.d.) of two nonnegative integers is the largest integer that divides evenly into both. In the third century B.C., the Greek mathematician Euclid discovered that the greatest common divisor of x and y can always be computed as follows:

If x is evenly divisible by y, then y is the greatest common divisor. Otherwise, the greatest common divisor of x and y is always equal to the greatest common divisor of y and the remainder of x divided by y


private static int gcdmethod(int i, int j) {

if (i%j==0) {
return j;
}
return gcdmethod(j,i%j);
}

}

No comments:

Post a Comment