In this example we will Learn how to write a C Program to print Pascal’s triangle as below.
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1
/********************************************************************** 1. Pascal triangle in c without using array 2. C code to print Pascal triangle 3. Simple c program for Pascal triangle 4. C program to generate Pascal triangle 5. Pascal triangle program in c language 6. C program to print Pascal triangle using for loop **********************************************************************/ #include<stdio.h> long fact(int num){ long f=1; int i=1; while(i<=num){ f=f*i; i++; } return f; } int main(){ int line,i,j; printf("Enter the no. of lines: "); scanf("%d",&line); for(i=0;i<line;i++){ for(j=0;j<line-i-1;j++) printf(" "); for(j=0;j<=i;j++) printf("%ld ",fact(i)/(fact(j)*fact(i-j))); printf("\n"); } return 0; } /* OUTPUT: Enter the no. of lines: 11 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 1 10 45 120 210 252 210 120 45 10 1 */
Leave a Reply