Pascal 's Triangle | binomialCoeff ; A simple O ( n ^ 3 ) program for Pascal ' s ▁ Triangle ▁ Function ▁ to ▁ print ▁ first ▁ n ▁ lines ▁ of ▁ Pascal ' s Triangle ; Iterate through every line and print entries in it ; Every line has number of integers equal to line number ; Driver program
def binomialCoeff ( n , k ) : NEW_LINE INDENT res = 1 NEW_LINE if ( k > n - k ) : NEW_LINE INDENT k = n - k NEW_LINE DEDENT for i in range ( 0 , k ) : NEW_LINE INDENT res = res * ( n - i ) NEW_LINE res = res // ( i + 1 ) NEW_LINE DEDENT return res NEW_LINE DEDENT def printPascal ( n ) : NEW_LINE INDENT for line in range ( 0 , n ) : NEW_LINE INDENT for i in range ( 0 , line + 1 ) : NEW_LINE INDENT print ( binomialCoeff ( line , i ) , " ▁ " , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT n = 7 NEW_LINE printPascal ( n ) NEW_LINE