Maximize the division result of Array using given operations | C ++ implementation to maximize the result of division of the given array elements ; Function to find the max result ; Sort the array in descending order ; loop to divide in this order arr [ 0 ] / ( arr [ 1 ] / arr [ 2 ] / ... . arr [ n - 2 ] / arr [ n - 1 ] ) ; return the final result ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float maxDivision ( int arr [ ] , int n ) { sort ( arr , arr + n , greater < int > ( ) ) ; float mxdiv = arr [ 1 ] ; for ( int i = 2 ; i < n ; ++ i ) mxdiv = mxdiv / arr [ i ] ; return arr [ 0 ] / mxdiv ; } int main ( ) { int arr [ ] = { 100 , 1000 , 10 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxDivision ( arr , n ) ; return 0 ; }