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 ; Sort the array ; Initialize smallest element of the array ; Initialize largest element of the array ; Print second largest product pair ; Driver Code ; Given array ; Function Call
using System ; class GFG { static void maxProduct ( int [ ] arr , int N ) { if ( N < 3 ) { return ; } Array . Sort ( arr ) ; int smallest1 = arr [ 0 ] ; int smallest3 = arr [ 2 ] ; int largest1 = arr [ N - 1 ] ; int largest3 = arr [ N - 3 ] ; if ( smallest1 * smallest3 >= largest1 * largest3 ) { Console . Write ( smallest1 + " ▁ " + smallest3 ) ; } else { Console . Write ( largest1 + " ▁ " + largest3 ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 2 , 67 , 45 , 160 , 78 } ; int N = arr . Length ; maxProduct ( arr , N ) ; } }