Thursday, 21 July 2016

PASCALS'S TRIANGLE IS A GEOMETRIC ARRANGEMENT OF THE BINOMIAL COEFFICIENT'S IN A TRIANGLE. IT IS NAMED AFTER BLAISE PASCAL. WAP TO DISPAY N LINES OF THE TRIANGLE

              1
            1  1
          1  2  1
        1  3  3  1
      1  4  6  4  1
    1 5 10 10  5 1
  1 6 15 20 15 6 1

#include<stdio.h>
int fact(int);
main()
{
int k, c,n1,n2,n3,n,j;
printf("Enter the value of n");
scanf("%d",&n);
for(k=1;k<=n;k++)
{
for(j=1;j<=k;j++)
{
int i=0;
n1=fact(j);
n2=fact(j-1);
n3=fact(i);
c=n1/(n2*n3);
printf("%d",c);
i++;
}
printf("\n");
}
}
int fact(int a)
{
int fact=1,j;
if(a>0)
{
for(j=1;j<=a;j++)
{
fact=fact*j;
}
}
else
fact=1;
return fact;
}


No comments:

Post a Comment