Showing posts with label euclids. Show all posts
Showing posts with label euclids. Show all posts
Wednesday, November 7, 2012
Java Program to find GCD , LCM of two numbers
Greatest common divisor (gcd)
The greatest common divisor (gcd)( also known as the greatest common factor (gcf), or highest common factor(hcf)) of two or more non-zero integers, is the largest positive integer that divides the numbers without a remainder.
For example, the GCD of 8 and 12 is 4.
Euclid's algorithm
Euclid's algorithm uses a division algorithm such as long division in combination with the observation that the gcd of two numbers also divides their difference.
Formally the algorithm can be described as,
gcd(a,0) = a (1)
gcd(a,b) = gcd(b, a mod b) (2)
Labels:
algorithm,
euclids,
gcd,
greatest common divisor,
Java,
lcm,
least common multiple,
program
Subscribe to:
Posts (Atom)