text: Sum of all products of the Binomial Coefficients of two numbers up to K | Function returns nCr i . e . Binomial Coefficient ; Initialize res with 1 ; Since C ( n , r ) = C ( n , n - r ) ; Evaluating expression ; Driver code
code: function nCr ( n , r ) { let res = 1 ; if ( r > n - r ) r = n - r ; for ( let i = 0 ; i < r ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } let n = 3 , m = 2 , k = 2 ; document . write ( nCr ( n + m , k ) ) ;