Length and Breadth of rectangle such that ratio of Area to diagonal ^ 2 is maximum | C # for finding maximum p ^ 2 / A ratio of rectangle ; function to print length and breadth ; sort the input array ; create array vector of integers occurring in pairs ; push the same pairs ; calculate length and breadth as per requirement ; check for given condition ; print the required answer ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void findLandB ( int [ ] arr , int n ) { Array . Sort ( arr ) ; List < Double > arr_pairs = new List < Double > ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { arr_pairs . Add ( ( double ) arr [ i ] ) ; i ++ ; } } double length = arr_pairs [ 0 ] ; double breadth = arr_pairs [ 1 ] ; double size = arr_pairs . Count ; for ( int i = 2 ; i < size ; i ++ ) { if ( ( length / breadth + breadth / length ) > ( arr_pairs [ i ] / arr_pairs [ i - 1 ] + arr_pairs [ i - 1 ] / arr_pairs [ i ] ) ) { length = arr_pairs [ i ] ; breadth = arr_pairs [ i - 1 ] ; } } Console . Write ( ( int ) length + " , ▁ " + ( int ) breadth + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 2 , 2 , 2 , 5 , 6 , 5 , 6 , 7 , 2 } ; int n = arr . Length ; findLandB ( arr , n ) ; } }