PASCAL TRIANGLE USING C
To write a c program to print the Pascal triangle using nested for loop.
/*PASCAL TRIANGLE*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],n,j,k,i;
clrscr();
printf("PASCAL TRIANGLE");
printf("\nEnter value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=n;k>=i;k--)
printf("\n");
printf("");
for(j=1;j<=i;j++)
{
if(j==1||j==i)
{
a[i-1][j-1]=1;
}
else
{
a[i-1][j-1]=a[i-2][j-2]+a[i-2][j-1];
}
printf("\t%d",a[i-1][j-1]);
}
printf("\n\n\n");
}
getch();
}
OUTPUT:
PASCAL TRIANGLE
Enter value5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Comments
Post a Comment