Showing posts with label pattern in c. Show all posts
Showing posts with label pattern in c. Show all posts

Saturday, December 31, 2011

C Program For Pascal's Triangle - Pattern Pascal's Triangle in C Programming

It is a triangle array of the binomial coefficients. In this program input value for rows of pascal's triangle.
To get element of particular location by adding upper level(above) left value and above right value.


Program Code
//C Program to generate pascal triangle
#include"stdio.h"
#include"conio.h"
void main()
{
 int num,c,i,j,k;
 clrscr();
 printf("\nenter number of rows for pascal triangle: ");
 scanf("%d",&num);
 printf("\n\t********PASCAL TRIANGLE********\n\n");
 for(i=0;i<num;i++)
 {
  c = 1;
  for(j=0;j<num-i;j++)
  {
   printf("   ");
  }
  for(k = 0;k<=i;k++)
  {
   printf("   ");
   printf("%d",c); 
   printf(" ");
   c = c * (i - k) / (k + 1);
  }
  printf("\n");
  printf("\n");
 }
 printf("\n");
 getch();
}

Output