Product of given N fractions in reduced form | Java program to find product of 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
import java . io . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static void productReduce ( int n , int num [ ] , int den [ ] ) { int new_num = 1 , new_den = 1 ; for ( int i = 0 ; i < n ; i ++ ) { new_num *= num [ i ] ; new_den *= den [ i ] ; } int GCD = gcd ( new_num , new_den ) ; new_num /= GCD ; new_den /= GCD ; System . out . println ( new_num + " / " + new_den ) ; } public static void main ( String [ ] args ) { int n = 3 ; int num [ ] = { 1 , 2 , 5 } ; int den [ ] = { 2 , 1 , 6 } ; productReduce ( n , num , den ) ; } }