Write a C Program to print Pascal triangle:
Overview:
First of all, in this article, I will give you a general introduction of the Pascal Triangle. Then, I will write c program to print the Pascal triangle. After all, I will show its output as a Pascal triangle in front of you.
Table of contents:
- What is Pascal’s Triangle?
- Demonstration of Pascal’s Triangle
- C program to print pascal triangle
- Conclusion
What is Pascal’s Triangle?
Pascal’s triangle, in algebra, a triangular arrangement of numbers that gives the coefficients in the expansion of any binomial expression, such as (x + y)n. It is named for the 17th-century French mathematician Blaise Pascal.
To find nth term of a Pascal triangle we use the following formula.
Demonstration of Pascal Triangle
C program to print pascal triangle
#include <stdio.h> /* Function definition */ long long fact(int n); int main() { int n, k, row, i; long long term; /* Input number of rows */ printf("Enter number of rows : "); scanf("%d", &row); for(n=0; n<row; n++) { /* Prints 3 spaces */ for(i=n; i<=row; i++) printf("%3c", ' '); /* Generate term for current row */ for(k=0; k<=n; k++) { term = fact(n) / (fact(k) * fact(n-k)); printf("%6lld", term); } printf("\n"); } return 0; } /**Function to calculate factorial */ long long fact(int n) { long long factorial = 1ll; while(n>=1) { factorial *= n; n--; } return factorial; }
Conclusion:
Pascal Triangle is named as the Mathematician Blaise Pascal. This Program shows a Pascal Triangle in front of you as a output.