C++ Program to print a Pascal Triangle upto N depth
Pascal Triangle is a triangular array of binomial coefficients, named after Blaise Pascal. In this triangle, the subsequent rows are relative to the numbers in the previous row. The triangle is constructed in following manner, at the top most row, there is only a single element, usually 1. The next row is written in such a way that the element represent the sum of the top left and top right element, therefore leaving the space blank directly under the top element. Here’s a picture that explains it better. [Read more: Pascal's triangle]
In this program, we will print a pascal triangle up to n depth or n rows. Here the number of rows (n) will be entered by users and then a pascal triangle will be generated in a 2D manner.
The leftmost and the rightmost numbers in the row are represented by 1. Since the top left of each row is taken as 0, so 0+1 gives 1. Here, as you can see, 2 is represented by addition of top-left 1 and top-right 1. Similarly, 3 in the next row is the result of addition of top-left 1 and top-right 2. This continues upto n number of rows.