0% found this document useful (0 votes)
5 views1 page

Pascal

This C program prompts the user to enter the number of rows and then prints Pascal's triangle based on that input. It uses nested loops to calculate and display the coefficients for each row. The program utilizes a formula to compute the coefficients dynamically as it iterates through the rows and columns.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Pascal

This C program prompts the user to enter the number of rows and then prints Pascal's triangle based on that input. It uses nested loops to calculate and display the coefficients for each row. The program utilizes a formula to compute the coefficients dynamically as it iterates through the rows and columns.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1 #include <stdio.

h>
2 int main() {
3 int rows, coef = 1, space, i, j;
4 printf("Enter the number of rows: ");
5 scanf("%d", &rows);
6 for (i = 0; i < rows; i++) {
7 for (space = 1; space <= rows - i; space++)
8 {
9 printf(" ");
10 }
11 for (j = 0; j <= i; j++) {
12 if (j == 0 || i == 0)
13 {
14 coef = 1;
15 }
16 else
17 {
18 coef = coef * (i - j + 1) / j;
19
20 }
21 printf(" %d", coef);
22 }
23 printf("\n");
24 }
25 return 0;
26 }
27

You might also like