C Program To Print Pascal Triangle
Learn How To Print Pascal Triangle in C Programming Language. It is important that we should know How A For Loop Works before getting further with the C Program Code.
About Pascal’s Triangle
Pascal’s Traingle is named after a famous mathematician Blaise Pascal. Pascal Triangle is an Array of Binomial Co – Efficients in a Triangular Format. Pascal Triangle includes Calculation of Factorial of a Number and then processing the next digit. This Pascal Triangle is generated using For Loop.
Note: This Code to Generate Pascal Triangle in C Programming has been compiled with GNU GCC Compiler and developed with gEdit Editor and Terminal in Linux Ubuntu Terminal Operating System.
Method 1: C Program To Print Pascal Triangle 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 26 27 28 29 30 31 32 33 34 | #include <stdio.h> long fact(int); int main() { int i, limit, count; printf("\nEnter The Rows To Be Printed:\t"); scanf("%d", &limit); for (i = 0; i < limit; i++) { for(count = 0; count <= (limit - i - 2); count++) { printf(" "); } for(count = 0; count <= i; count++) { printf("%ld ", fact(i)/(fact(count) * fact(i - count))); } printf("\n"); } return 0; } long fact(int limit) { int i; long fact = 1; for(i = 1; i <= limit; i++) { fact = fact * i; } return fact; } |
Method 2: Code To Display Pascal Triangle in C Programming using While 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <stdio.h> long fact(int); int main() { int i, limit, count; printf("\nEnter The Rows To Be Printed:\t"); scanf("%d", &limit); i = 0; while(i < limit) { count = 0; while(count <= (limit - i - 2)) { printf(" "); count++; } count = 0; while(count <= i) { printf("%ld ", fact(i)/(fact(count) * fact(i - count))); count++; } i++; printf("\n"); } return 0; } long fact(int limit) { int i; long fact = 1; i = 1; while(i <= limit) { fact = fact * i; i++; } return fact; } |
Output

If you have any doubts or Compilation Errors in this C Program To Print Pascal Triangle, let us know about about it in the Comment Section below.