News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Calculate the Pascal triangle

Started by OmMuruga, Jan 14, 2009, 10:55 PM

Previous topic - Next topic

OmMuruga

To calculate the Pascals Triangle for given number .

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10];
int i,j,c,n;
clrscr();
printf("Enter how many lines do you want");
scanf("%d",&n);
a[1][1]=1;
printf("%5d",a[1][1]);
a[2][1]=1;a[2][2]=2;a[2][3]=1;
printf("%d %d %d",a[2][1],a[2][2],a[2][3]);
for(i=3;i<=n;i++)
  {
   a[1]=1;
   printf("%d",a[1]);
   j=2;c=3;
   while(j<=i)
   {
    a[j]=a[i-1][c-1]+a[i-1][c-2];
    printf("%5d",a[j]);
    c=c+1;
    j=j+1;
   }
a[j]=1;
printf("%d",a[j]);
}
}
:acumen

nandagopal



This code works perfectly but little explanation needed !!!!




pradeep prem

this is easy program to solve this easy with loop