C program to print Pascal triangle

Program to print Pascal's Triangle

C program to print Pascal triangle

Pascal’s triangle is a triangular array of binomial coefficients. All values outside the triangle are considered as zero (0). The first row is 0 1 0 whereas only 1 acquires space in pascal’s triangle, 0s are invisible. The second row is acquired by adding (0+1) and (1+0).

So, let’s go forward to implement our program…

#include <stdio.h>
#include<conio.h>

int facto(int n) {
   int f;
   for(f = 1; n > 1; n--)
      f *= n;
   return f;
}
int ncr(int n,int r) {
   return facto(n) / ( facto(n-r) * facto(r) );
}

void main() {
   int num, i, j;
   num = 5;
   clrscr();
printf("\t\t\t...Welcome To EduNews.Tech...\n");
   for(i = 0; i <= num; i++) {
      for(j = 0; j <= num-i; j++)
         printf("  ");  
      for(j = 0; j <= i; j++)
         printf(" %3d", ncr(i, j));
      printf("\n");

   }
   printf("\n\n\n\n\t\t\tThankyou for Joining Us !");
    printf("\n\t\t\t!Regards EduNews !");

getch();
}

Program Output:

pascal triangle

I hope this post helps you to understand Pascal Triangle and its implementation in C programming language.

Keep coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *