Pascal 's Triangle | JavaScript program for Pascal ' s ▁ Triangle ▁ A ▁ O ( n ^ 2 ) ▁ time ▁ and ▁ O ( 1 ) ▁ extra ▁ space ▁ method ▁ for ▁ Pascal ' s Triangle Pascal function ; used to represent C ( line , i ) ; The first value in a line is always 1 ; Driver code
function printPascal ( n ) { for ( line = 1 ; line <= n ; line ++ ) { var C = 1 ; for ( i = 1 ; i <= line ; i ++ ) { document . write ( C + " " ) ; C = C * ( line - i ) / i ; } document . write ( " " ) ; } } var n = 5 ; printPascal ( n ) ;