Pascal triangle
a triangular arrangement of numbers that gives the coefficients in the expansion of any binomial expression, such as (x + y) n. let's see the program to be more clear about this,
Program
QUESTION:- write a c program to print the pascal triangle as shown below.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
#include <stdio.h>
#include <conio.h>
void main()
{
int row, col, space, no, li;
printf("enter a valuento print pascal triangle: ");
scanf("%d", &li);
// rows
for (row = 0; row <= li; row++)
{
// space
for (space = 0; space <= (li - row); space++)
{
printf(" ");
}
no = 1;
// pascal triangle
for (col = 0; col <= row; col++)
{
printf("%d ", no);
no = no * (row - col) / (col + 1);
}
printf("\n");
}
getch();
}
OUTPUT
enter a valuento print pascal triangle: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
0 Comments