Mean of minimum of all possible K | C # code for the above approach ; Function to find the value of nCr ; Base Case ; Find nCr recursively ; Function to find the expected minimum values of all the subsets of size K ; Find the factorials that will be used later ; Find the factorials ; Total number of subsets ; Stores the sum of minimum over all possible subsets ; Iterate over all possible minimum ; Find the mean over all subsets ; Driver Code
using System ; public class GFG { static int nCr ( int n , int r , int [ ] f ) { if ( n < r ) { return 0 ; } return f [ n ] / ( f [ r ] * f [ n - r ] ) ; } static int findMean ( int N , int X ) { int [ ] f = new int [ N + 1 ] ; f [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { f [ i ] = f [ i - 1 ] * i ; } int total = nCr ( N , X , f ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { count += nCr ( N - i , X - 1 , f ) * i ; } double E_X = ( double ) ( count ) / ( double ) ( total ) ; Console . Write ( " { 0 : F9 } " , E_X ) ; return 0 ; } static publ int N = 3 , X = 2 ; findMean ( N , X ) ; } } void Main ( ) {