text: Calculate nCr using Pascal 's Triangle | C # implementation of the approach ; Initialize the matrix with 0 ; 0 C0 = 1 ; Set every nCr = 1 where r = 0 ; Value for the current cell of Pascal 's triangle ; Function to return the value of nCr ; Return nCr ; Driver code ; Build the Pascal 's triangle
code: using System ; class GFG { static int [ , ] l = new int [ 1001 , 1001 ] ; static void initialize ( ) { l [ 0 , 0 ] = 1 ; for ( int i = 1 ; i < 1001 ; i ++ ) { l [ i , 0 ] = 1 ; for ( int j = 1 ; j < i + 1 ; j ++ ) { l [ i , j ] = ( l [ i - 1 , j - 1 ] + l [ i - 1 , j ] ) ; } } } static int nCr ( int n , int r ) { return l [ n , r ] ; } public static void Main ( ) { initialize ( ) ; int n = 8 ; int r = 3 ; Console . WriteLine ( nCr ( n , r ) ) ; } }