Даны две дроби a/b и c/d (a,b,c,d - натуральные числа). составить программу умножения дроби на дробь. ответ должен быть несократимой дробью. использовать подпрограмму алгоритма Евклида для определения НОД
def gcd(a, b): while b: a, b = b, a % b return a def multiply_fractions(a, b, c, d): numerator = a * c denominator = b * d common_divisor = gcd(numerator, denominator) numerator /= common_divisor denominator /= common_divisor return int(numerator), int(denominator) a = int(input("Enter the numerator of the first fraction: ")) b = int(input("Enter the denominator of the first fraction: ")) c = int(input("Enter the numerator of the second fraction: ")) d = int(input("Enter the denominator of the second fraction: ")) result_numerator, result_denominator = multiply_fractions(a, b, c, d) print("The result of multiplying the fractions is: {}/{}".format(result_numerator, result_denominator))
while b:
a, b = b, a % b
return a
def multiply_fractions(a, b, c, d):
numerator = a * c
denominator = b * d
common_divisor = gcd(numerator, denominator)
numerator /= common_divisor
denominator /= common_divisor
return int(numerator), int(denominator)
a = int(input("Enter the numerator of the first fraction: "))
b = int(input("Enter the denominator of the first fraction: "))
c = int(input("Enter the numerator of the second fraction: "))
d = int(input("Enter the denominator of the second fraction: "))
result_numerator, result_denominator = multiply_fractions(a, b, c, d)
print("The result of multiplying the fractions is: {}/{}".format(result_numerator, result_denominator))