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 . ; Driven Program
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function productReduce ( n , num , den ) { let new_num = 1 , new_den = 1 ; for ( let i = 0 ; i < n ; i ++ ) { new_num *= num [ i ] ; new_den *= den [ i ] ; } let GCD = gcd ( new_num , new_den ) ; new_num /= GCD ; new_den /= GCD ; document . write ( new_num + " " + new_den ) ; } let n = 3 ; let num = [ 1 , 2 , 5 ] ; let den = [ 2 , 1 , 6 ] ; productReduce ( n , num , den ) ;