Ways of selecting men and women from a group to make a team | Returns factorial of the number ; Function to calculate ncr ; Function to calculate the total possible ways ; Driver code
function fact ( n ) { var fact = 1 ; for ( i = 2 ; i <= n ; i ++ ) fact *= i ; return fact ; } function ncr ( n , r ) { var ncr = fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; return parseInt ( ncr ) ; } function ways ( m , w , n , k ) { var ans = 0 ; while ( m >= k ) { ans += ncr ( m , k ) * ncr ( w , n - k ) ; k += 1 ; } return parseInt ( ans ) ; } var m , w , n , k ; m = 7 ; w = 6 ; n = 5 ; k = 3 ; document . write ( ways ( m , w , n , k ) ) ;