To get element of particular location by adding upper level(above) left value and above right value.
Program Code
//C Program to generate pascal triangle #include"stdio.h" #include"conio.h" void main() { int num,c,i,j,k; clrscr(); printf("\nenter number of rows for pascal triangle: "); scanf("%d",&num); printf("\n\t********PASCAL TRIANGLE********\n\n"); for(i=0;i<num;i++) { c = 1; for(j=0;j<num-i;j++) { printf(" "); } for(k = 0;k<=i;k++) { printf(" "); printf("%d",c); printf(" "); c = c * (i - k) / (k + 1); } printf("\n"); printf("\n"); } printf("\n"); getch(); }
Output