-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathquestion8.c
59 lines (35 loc) · 854 Bytes
/
question8.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
1. Write a C program to print "Pascal's Triangle".
The numbers in the r-th row of Pascal's triangle represent
the coefficients in the Binomial expansion of (a+b)^{r-1}.
The first four rows of Pascal triangle are shown below :-
1
1 1
1 2 1
1 3 3 1
input: Number of rows of Pascal triangle to print
output: Resultant Pascal's Triangle [3]
*/
#include <stdio.h>
int main(){
int i,j,k,q,rows;
printf("enter the number of rows:\n");
scanf("%d", &rows);
int prev[rows];
for(i=0; i< rows; i++){
int temp[rows];
temp[0] = 1;
for(j=rows-i; j > 0; j--){
printf("%s"," ");
}
for(k = 1; k < i+1; k++){
temp[k] = prev[k] + prev[k-1];
}
temp[i] = 1;
for(q = 0; q< i+1; q++){
printf("%d %s", temp[q], " ");
prev[q] = temp[q];
}
printf("\n");
}
}