Program to generate Pascal's triangle
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int b, p, q, r, x;
clrscr();
b = 1;
q = 0;
printf("Enter the number of rows : ");
scanf("%d", &p);
printf("\nPascal's triangle is : \n\n");
while (q < p)
{
for(r = 40 - 3 * q ; r > 0 ; --r)
printf(" ");
for(x = 0 ; x <= q ; ++x)
{
if((x == 0) || (q == 0))
b = 1;
else
b = (b * (q - x 1)) / x;
printf("%6d", b);
}
printf("\n\n");
q;
}
getch();
}
Output:
Enter the number of rows : 5
Pascal's triangle is :
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
-
UpdatedDec 30, 2019
-
Views6,983
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order