Minimum sum of product of elements of pairs of the given array | C ++ program to find the minimum product of sum of pair of element in array arr [ ] ; Function to find the minimum product ; Sort the array using STL sort ( ) function ; Initialise product to 1 ; Find product of sum of all pairs ; Return the product ; Driver code ; Function call to find product
#include " bits / stdc + + . h " NEW_LINE using namespace std ; int minimumProduct ( int * arr , int n ) { sort ( arr , arr + n ) ; int product = 1 ; for ( int i = 0 ; i < n ; i += 2 ) { product *= ( arr [ i ] + arr [ i + 1 ] ) ; } return product ; } int main ( ) { int arr [ ] = { 1 , 6 , 3 , 1 , 7 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimumProduct ( arr , n ) << endl ; return 0 ; }