Pascal triangle c program : Pascal’s Triangle is an infinite triangular array of numbers beginning with a 1 at the top. Pascal’s Triangle can be constructed starting with just the 1 on the top by following one easy rule: suppose you are standing in the triangle and would like to know which number to put in the position you are standing on. Look up and to the left, then up and to the right, sum the numbers and you have the entry of Pascal’s Triangle corresponding to your current location. Rows 0 thru 12 of Pascal’s Triangle look like

## Pascal triangle in C 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 30 31 32 33 | #include <stdio.h> //function to calculate factorial long fact(int x) { int i; long f=1; for(i=1;i<=x;++i) { f=f*i; } return f; } int main() { int i,j,k,n; printf("How many lines? "); scanf(" %d",&n); for(i=0;i< n;++i) { //loop to print spaces at starting of each row for(j=1;j<=(n-i-1);++j) { printf(" "); } //loop to calculate each value in a row and print it for(k=0;k<=i;++k) { printf(" %d ",fact(i)/(fact(i-k)*fact(k))); } printf(" \n"); //print new line after each row } return 0; } |

**OUTPUT for Pascal triangle in C program **

You can learn about more about C programs and for more quries go to quora