Find the Nth row in Pascal 's Triangle | C # program to find the Nth index row in Pascal 's triangle ; Function to find the elements of rowIndex in Pascal 's Triangle ; 1 st element of every row is 1 ; Check if the row that has to be returned is the first row ; Generate the previous row ; Generate the elements of the current row by the help of the previous row ; Return the row ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static List < int > getRow ( int rowIndex ) { List < int > currow = new List < int > ( ) ; currow . Add ( 1 ) ; if ( rowIndex == 0 ) { return currow ; } List < int > prev = getRow ( rowIndex - 1 ) ; for ( int i = 1 ; i < prev . Count ; i ++ ) { int curr = prev [ i - 1 ] + prev [ i ] ; currow . Add ( curr ) ; } currow . Add ( 1 ) ; return currow ; } public static void Main ( String [ ] args ) { int n = 3 ; List < int > arr = getRow ( n ) ; for ( int i = 0 ; i < arr . Count ; i ++ ) { if ( i == arr . Count - 1 ) Console . Write ( arr [ i ] ) ; else Console . Write ( arr [ i ] + " , ▁ " ) ; } } }