-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintPascalTriangle.c
51 lines (34 loc) · 967 Bytes
/
PrintPascalTriangle.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
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int main() {
// Write C++ code here
int p,q;
int a[100][100];
int n,m;
cin>>n;
m = n;
for(int i=0; i<n; i++){
// for(int j=4; j>=i; j--)
// cout<<" ";
if(i>1)
p=0,q=1;
for(int k=0; k<=i; k++){
if(i <= 1 || k==0 || k==i)
a[i][k] = 1;
else{
a[i][k] = a[i-1][p]+a[i-1][q];
p++;
q++;
}
}
}
for(int i=0; i<n; i++){
for(int j=n-1; j>=i; j--)
cout<<" ";
for(int k=0; k<=i; k++)
cout<<a[i][k]<<" ";
cout<<"\n";
}
return 0;
}