text: Mean of array generated by products of all pairs of the given array | C # program for the above approach ; Function to find the mean of pair product array of [ ] arr ; Store product of pairs ; Generate all unordered pairs ; Store product of pairs ; Size of pairArray ; Store sum of pairArray ; Stores the mean of pairArray [ ] ; Find mean of pairArray [ ] ; Return the resultant mean ; Driver Code ; Given array [ ] arr ; Function Call
code: using System ; using System . Collections . Generic ; class GFG { static double pairProductMean ( int [ ] arr , int N ) { List < int > pairArray = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int pairProduct = arr [ i ] * arr [ j ] ; pairArray . Add ( pairProduct ) ; } } int length = pairArray . Count ; float sum = 0 ; for ( int i = 0 ; i < length ; i ++ ) sum += pairArray [ i ] ; float mean ; if ( length != 0 ) mean = sum / length ; else mean = 0 ; return mean ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 4 , 8 } ; int N = arr . Length ; Console . WriteLine ( " { 0 : F2 } " , pairProductMean ( arr , N ) ) ; } }