Find a pair in Array with second largest product | C # program for the above approach ; Function to find second largest product pair in arr [ 0. . n - 1 ] ; No pair exits ; Initialize max product pair ; Traverse through every possible pair and keep track of largest product ; If pair is largest ; Second largest ; If pair dose not largest but larger then second largest ; Print the pairs ; Driver Code ; Given array ; Function call
using System ; class GFG { static void maxProduct ( int [ ] arr , int N ) { if ( N < 3 ) { return ; } int a = arr [ 0 ] , b = arr [ 1 ] ; int c = 0 , d = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = i + 1 ; j < N - 1 ; j ++ ) { if ( arr [ i ] * arr [ j ] > a * b ) { c = a ; d = b ; a = arr [ i ] ; b = arr [ j ] ; } if ( arr [ i ] * arr [ j ] < a * b && arr [ i ] * arr [ j ] > c * d ) c = arr [ i ] ; d = arr [ j ] ; } Console . WriteLine ( c + " ▁ " + d ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 2 , 67 , 45 , 160 , 78 } ; int N = arr . Length ; maxProduct ( arr , N ) ; } }