c program for pascal triangle with output

C program for Pascal triangle with output:

Program:



#include<stdio.h>
void main()
 {
  int r,c,i, j,k;
  printf("Enter Number of Rows:\n");
  scanf("%d",&r);
  for(i=0;i<r;i++)      //controls the rows in triangle
   {
     for(j=40-3*i;j>=0;j--)    //controls the space in rows
printf(" ");
     for(k=0;k<=i;k++)
{
  if(k==0 || i==0)          //Value to print 
      c=1;
  else
      c=c*(i-k+1)/k;
   printf("%6d",c);
}
printf("\n");
   }
 }


Output:


Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment