Editorial Staff - - C Programming Tutorial
Today, we are going to share a C program to print pascal triangle with the output. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as we are going to share a C program to print pascal triangle.
We have designed this program for beginners for learning purpose. Copy below c program and execute it with c compiler to see the output of the program.
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 | #include <stdio.h> long fact (int); int main () { int n, i, j; printf ("Please enter number of rows you would like to see in pascal triangle\n"); scanf ("%d", &n); printf ("Pascal Triangle pattern:\n"); for (i = 0; i < n; i++) { for (j = 0; j <= (n - i - 2); j++) printf (" "); for (j = 0; j <= i; j++) printf ("%ld ", fact (i) / (fact (j) * fact (i - j))); printf ("\n"); } return 0; } long fact (int n) { int c; long result = 1; for (c = 1; c <= n; c++) { result = result * c; } return (result); } |
Please enter number of rows you would like to see in pascal triangle
6
Pascal Triangle pattern:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Editorial Staff at FreeWebMentor is a team of professional developers leads by Prem Tiwari View all posts by Editorial Staff