Program to print the pattern 1020304017018019020 * * 50607014015016 * * * * 809012013 * * * * * * 10011. . . | Function to find the sum of N integers from 1 to N ; Function to print the given pattern ; Iterate over [ 0 , N - 1 ] ; Sub - Pattern - 1 ; Sub - Pattern - 2 ; Count the number of element in rows and sub - pattern 2 and 3 will have same rows ; Increment Val to print the series 1 , 2 , 3 , 4 , 5 ... ; Finally , add the ( N - 1 ) th element i . e . , 5 and increment it by 1 ; Initial is used to give the initial value of the row in Sub - Pattern 3 ; Sub - Pattern 3 ; Skip printing zero at the last ; Given N ; Function Call
function sum ( n ) { return n * parseInt ( ( n - 1 ) / 2 ) ; } function BSpattern ( N ) { var Val = 0 , Pthree = 0 , cnt = 0 , initial ; var s = " " ; for ( var i = 0 ; i < N ; i ++ ) { cnt = 0 ; if ( i > 0 ) { document . write ( s ) ; s += " " ; } for ( var j = i ; j < N ; j ++ ) { if ( i > 0 ) { cnt ++ ; } document . write ( ++ Val ) ; document . write ( 0 ) ; } if ( i == 0 ) { var Sumbeforelast = sum ( Val ) * 2 ; Pthree = Val + Sumbeforelast + 1 ; initial = Pthree ; } initial = initial - cnt ; Pthree = initial ; for ( var k = i ; k < N ; k ++ ) { document . write ( Pthree ++ ) ; if ( k != N - 1 ) { document . write ( 0 ) ; } } document . write ( " " ) ; } } var N = 5 ; BSpattern ( N ) ;