Pascal's Triangle
This is a triangular array of binomial coefficients. This program is entry value for the lines of Pascal's triangle.
Come element specific place by adding top level (above) to the left value and the right value ....
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i,j,k;
int num;
clrscr();
printf("\n Enter number of rows for pascal's triangle: ");
scanf("%d",&num);
printf("\n\t******PASCAL'S TRIANGLE******\n\n");
for(i=0;i<num;i++)
{
a = 1;
for(j=0;j<num-i;j++)
{
printf(" ");
}
for(k = 0;k<=i;k++)
{
printf(" ");
printf("%d",a);
printf(" ");
a = a * (i - k) / (k + 1);
}
printf("\n");
printf("\n");
}
printf("\n");
getch();
}
This is a triangular array of binomial coefficients. This program is entry value for the lines of Pascal's triangle.
Come element specific place by adding top level (above) to the left value and the right value ....
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i,j,k;
int num;
clrscr();
printf("\n Enter number of rows for pascal's triangle: ");
scanf("%d",&num);
printf("\n\t******PASCAL'S TRIANGLE******\n\n");
for(i=0;i<num;i++)
{
a = 1;
for(j=0;j<num-i;j++)
{
printf(" ");
}
for(k = 0;k<=i;k++)
{
printf(" ");
printf("%d",a);
printf(" ");
a = a * (i - k) / (k + 1);
}
printf("\n");
printf("\n");
}
printf("\n");
getch();
}
No comments:
Post a Comment