You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
797 B
C

/*
* C Program to Display Pascal triangle
*/
#include <stdio.h>
void main()
{
int array[15][15], i, j, rows, num = 25, k;
printf("\n enter the number of rows:");
scanf("%d", &rows);
for (i = 0; i < rows; i++)
{
for (k = num - 2 * i; k >= 0; k--)
printf(" ");
for (j = 0; j <= i; j++)
{
if (j == 0 || i == j)
{
array[i][j] = 1;
}
else
{
array[i][j] = array[i - 1][j - 1] + array[i - 1][j];
}
printf("%4d", array[i][j]);
}
printf("\n");
}
}