Product of given N fractions in reduced form | Function to return gcd of a and b ; Print the Product of N fraction in Reduced Form . ; finding the product of all N numerators and denominators . ; Finding GCD of new numerator and denominator ; Converting into reduced form . ; Driver Code
def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b ; NEW_LINE DEDENT return gcd ( b % a , a ) ; NEW_LINE DEDENT def productReduce ( n , num , den ) : NEW_LINE INDENT new_num = 1 ; NEW_LINE new_den = 1 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT new_num = new_num * num [ i ] ; NEW_LINE new_den = new_den * den [ i ] ; NEW_LINE DEDENT GCD = gcd ( new_num , new_den ) ; NEW_LINE new_num = new_num / GCD ; NEW_LINE new_den = new_den / GCD ; NEW_LINE print ( int ( new_num ) , " / " , int ( new_den ) ) ; NEW_LINE DEDENT n = 3 ; NEW_LINE num = [ 1 , 2 , 5 ] ; NEW_LINE den = [ 2 , 1 , 6 ] ; NEW_LINE productReduce ( n , num , den ) ; NEW_LINE