How to write a C Program To Show Pascal Triangle in C Programming Language ?
Solution:
C Program To Show Pascal Triangle
long factorial(int);
main()
{
int i, n, c;
printf("Enter the number of rows you wish to see in pascal triangle\n");
scanf("%d",&n);
for ( i = 0 ; i < n ; i++ )
{
for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
printf(" ");
for( c = 0 ; c <= i ; c++ )
printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
printf("\n");
}
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for( c = 1 ; c <= n ; c++ )
result = result*c;
return ( result );
}
Learn More :
Triangle
- Waveform Generation (Triangle Wave) C Program
- C Program to Print Floyd's Triangle
- C Program Nested Loop (inverted Triangle) C Code
- Triangle Wave in C Program
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- Bitmap Triangle in C Program
- C Program to Rectangular Triangle Using Operator