Pascal triangle C program
C program to print Pascal triangle which you might have studied while studying Binomial Theorem in Mathematics. It takes an input value from the user i.e. number of rows and prints following patterns
[quote]
Rows you want to input: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
[/quote]
#include <stdio.h> int main() { int r,n,i,k,s; printf("\nRows you want to input: "); scanf("%d",&r); i=0; while(i<r) { printf("\n"); for(s=40-i*3; s>=1; s--) printf(" "); for(k=0; k<=i; k++) { if(k==0) n=1; else n=((i-k+1)*n)/k; printf("%6d",n); } ++i; } return 0; }