DESCRIPTION: This program prints the pyramid as below-
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
PROGRAM:
#include<stdio.h>
fact(int x)
{
int f=1,i;
for(i=x;i>0;i--)
f=f*i;
return f;
}
main()
{
int i,j,n,k;
printf("enter the value of n\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
printf(" ");
for(k=0;k<=i;k++)
printf("%2d",fact(i)/(fact(k)*fact(i-k)));
printf("\n");
}
}
OUTPUT WINDOW:
No comments:
Post a Comment