/*PROGRAM TO PRINT THE PASCAL TRIANGLE */
#include<stdio.h>
int ncr(int ,int );
int fact(int);
void main()
{
int n,i,j,k;
printf("enter number of rows \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(k=(n-i);k>0;k--)
printf(" ");
for(j=0;j<=i;j++)
{
printf("%d ",ncr(i,j));
}
printf("\n");
}
getch();
}
int ncr(int n,int r)
{
return (((fact(n))/(fact(n-r)*fact(r))));
}
int fact(int n)
{
if(n==0)
return 1;
else
return n*fact(n-1);
}
No comments:
Post a Comment