Pascal's triangle is a triangular array of the binomial coefficients. In much of the Western world it is named after French mathematician Blaise Pascal.
#include<stdio.h>
int main()
{
int i,j,l,binom;
printf("enter the no of lines=");
scanf("%d",&l);
for(i=1;i<=l;i++)
{
for(j=1;j<=l-i;j++)
printf(" ");
binom=1;
for(j=1;j<=i;j++)
{
printf("%d ",binom);
if(i==j+1)
binom=1;
else
binom=(binom*(i-j))/j;
}
printf("\n");
}
return 0;
}
OUTPUT-
enter the no of lines=6
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
#include<stdio.h>
int main()
{
int i,j,l,binom;
printf("enter the no of lines=");
scanf("%d",&l);
for(i=1;i<=l;i++)
{
for(j=1;j<=l-i;j++)
printf(" ");
binom=1;
for(j=1;j<=i;j++)
{
printf("%d ",binom);
if(i==j+1)
binom=1;
else
binom=(binom*(i-j))/j;
}
printf("\n");
}
return 0;
}
OUTPUT-
enter the no of lines=6
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Comments :
Post a Comment