/* C PROGRAM
FOR PASCAL TRIANGLE*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],r,i,j,t;
clrscr();
printf("\n\t\t PASCAL TRIANGLE");
printf("\n\t\t ~~~~~~~~~~~~~~~~");
printf("\n Enter the row values:");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
a[i][i]=1;
a[i][1]=1;
}
i=3;
while(i<=r)
{
t=2;
while(t<i)
{
a[i][t]=a[i-1][t-1]+a[i-1][t];
t++;
}
i++;
}
for(i=1;i<=r;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n\n");
}
getch();
}
OUTPUT:
PASCAL TRIANGLE
~~~~~~~~~~~~~~~~
Enter the row values: 5
1
1
1
1
2 1
1
3 3 1
1
4 6 4
1
0 comments:
Post a Comment