top of page

C program to print Pascal triangle

  • Writer: Jino Shaji
    Jino Shaji
  • Dec 31, 2014
  • 1 min read

Updated: Jun 9, 2020



Pascal Triangle in c: C program to print Pascal triangle which you might have studied in Binomial Theorem in Mathematics. Number of rows of Pascal triangle to print is entered by the user. First four rows of Pascal triangle are shown below :-

   1
  1 1
 1 2 1
1 3 3 1

Pascal triangle in c


#include 
 
long factorial(int);
 
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;
}

Output of program:

Pascal triangle program

Recent Posts

See All
Pointers In C

C Pointers Pointers in C are easy and fun to learn. Some C programming tasks are performed more easily with pointers, and other tasks,...

 
 
 

Comentarios


bottom of page