Pascal Triangle Program in C
Here, you will learn about the pascal triangle and get the program code to create a Pascal Triangle in C programming language.

What is Pascal Triangle?
Pascal’s Triangle is an arrangement of numbers in triangular foam, in which the numbers in each row are the coefficients in the expansion of (x+1)^n, where n is the row number, beginning with n=0.
The first row is n=0 and consists of the number 1. Each number in a row is the sum of right above two numbers.
Pascal Triangle Formula in C
Pascal triangle formula in c for nth row is given below:
C(n,k) = n! / (k! *(n-k)!)
in which nth is the rows and kth is the element.
Pascal Triangle in C program using For Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> int main() { int i , j , rows , sp , num = 1; printf("nnEnter number of rows: "); scanf("%d", &rows); for (i = 0; i < rows; i++) { for(sp=1; sp <= rows-i; sp++) printf(" "); for ( j = 0; j <= i; j++) { if (j == 0 || i == 0) num = 1; else num = num * (i - j + 1) / j; printf("%5d", num); } printf("\n"); } return 0; } |
Output
Check out our other C programming Examples