Example 40: Pascal's Triangle

Learn how to print a Pascal's triangle.

Problem

Write a program to generate Pascal’s triangle pattern shown below:

11

1   11 \space\space \space 1

1   2   11 \space \space\space 2 \space \space\space 1

1   3   3   11 \space\space \space 3 \space\space \space 3 \space\space \space 1

1   4   6   4   11 \space\space \space 4 \space\space \space 6 \space \space\space 4 \space\space \space 1

1   5   10   10   5   11 \space \space\space 5 \space \space \space10 \space \space \space 10 \space \space \space 5 \space \space \space 1

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.