C program to print Pascal triangle

Pascal Triangle is one of the most interesting number patterns. It is named after Blaise Pascal, a famous French Mathematician and Philosopher. To build the pascal triangle, we start with “1” at the top, then continue placing numbers below it in a triangular pattern. Each number is the two numbers above it added together except for the edges, which are all always 1.

The example of pascal triangle is shown below:

   1
  1 1
 1 2 1
1 3 3 1

Pascal triangle in c

#include <stdio.h>
#include <conio.h>
long factorial(int);
int main()
{
   int i, n, c;
   printf(" Enter the number of rows you want 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 );
}

Mohit Arora
Follow me