Pascal 's Triangle | binomialCoeff ; 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 Code
function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function printPascal ( n ) { for ( let line = 0 ; line < n ; line ++ ) { for ( let i = 0 ; i <= line ; i ++ ) document . write ( binomialCoeff ( line , i ) + " " ) ; document . write ( " " ) ; } } let n = 7 ; printPascal ( n ) ;