DreamsCoder.com

We Code your Dreams


home > Pascal triangle program in C language




Pascal triangle program in C language









#include
 
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 );
}

Label - c





by - Chinmay Mahajan





Are you looking for something else?


Suggested Programs




Spinning letters in using C - graphics


Pascal triangle program in C language


What is the difference between ARRAY and STACK?


Displaying Matrix in C