Make a new start with a new Thought!

NOTE :                // indicates comments.This wont get printed in the output.This is used for for documentation purpose. PROGRAM: #incl...

Pascal Triangle Program

NOTE :
              
// indicates comments.This wont get printed in the output.This is used for for documentation purpose.

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
  int n,i,j,k,pas;
  clrscr();
  printf("Enter the number of rows\t:\t");
  scanf("%d",&n);
  for(i=0;i<n;i++)                                   //No. of rows          
  {
    for(j=0;j<n-i;j++)                             //printing spaces
    {
       printf(" ");                         
    }
     pas=1;
     for(k=0;k<=i;k++)                      //pascal triangle
     {
         printf(" %d",pas);
         pas=pas*(i-k)/(k+1);
     }
      printf("\n");                           //next row
  }
 getch();
}

OUTPUT :


0 comments: