If you have a list of integers in python, say L = [4,8,12,24]
, how can you compute their greatest common denominator/divisor (4 in this case)?
Write a Python program to Compute the greatest common divisor (GCD) and least common multiple (LCM) of two integer. This python program allows the user to enter two positive integer values and compute GCD using while loop.
One way to do it is:
import fractions
def gcd(L):
return reduce(fractions.gcd, L)
print gcd([4,8,12,24])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With