C PROGRAM FOR PASCAL TRIANGLE
Pascal Triangle in c: C program to print Pascal triangle which you might have studied in Binomial Theorem in Mathematics. Number of rows of
Pascal triangle to print is entered by the user. First four rows of Pascal
triangle are shown below :-
1
1 1
1 2 1
1 3 3 1
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,j,num,x=1;
clrscr();
printf("Please Enter the Number :");
scanf("%d",&num);
printf("\n\n");
printf("OUTPUT:\n");
printf("------");
printf("\n\n");
printf("The Pascal triangle is\n");
printf("**********************\n");
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
{
if(j==1)
{
x=1;
printf("%d",x);
}
else
{
x=(x*(i-j+1)/(j-1));
printf("%d",x);
}
}
printf("\n");
}
getch();
}
0 comments:
Post a Comment