Explore
ProGrad Programs
Placement Prep
TCS Codevita
Webinars
About Us

Edit
Reply




Edit

Program to print Pascal's Triangle | FACE Prep

Published on 10 Mar 2020

Program to print Pascal's triangle is discussed here. Pascals triangle is a triangular array of the binomial coefficients.

The numbers outside Pascal's triangle are all "0". These "0s" are very important for the triangular pattern to work to form a triangular array. The triangle starts with a number "1" above, and any new number added below the upper number "1" is just the sum of the two numbers above, except for the edge, which is all "1".

pascal's triangle

row 0 =1

row 1 = (0+1), (1+0) = 1, 1

row 2 = (0+1), (1+1), (1+0) = 1, 2, 1

row 3 = (0+1), (1+2), (2+1), (1+0) = 1, 3, 3, 1

row 4 = (0+1), (1+3), (3+3), (3+1), (1+0) = 1, 4, 6, 4, 1

row 5 = (0+1), (1+4), (4+6), (6+4), (4+1),(1+0) = 1, 5, 10, 10, 5, 1

row 6 = (0+1), (1+5), (5+10), (10+10), (10+5), (5+1), (1+0) = 1, 6, 15, 20, 15, 6, 1


Program to print pascal's triangle


C
C++
Java
Python 3

Output
Enter the number of rows : 5
      1
     1 1
    1 2 1
   1 3 3 1
  1 4 6 4 1


Time complexity:O(n^2)


Recommended Programs






If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in