-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascals Triangle 1.cpp
More file actions
46 lines (44 loc) · 959 Bytes
/
Pascals Triangle 1.cpp
File metadata and controls
46 lines (44 loc) · 959 Bytes
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
#include <iostream>
using namespace std;
int main()
{
int t;
cin>>t;
long long int matrix[51][51];
matrix[0][0]=1;
matrix[1][0]=1;
matrix[1][1]=1;
while(t--)
{
int n;
cin>>n;
if(n==0)
cout<<1<<"\n";
else if(n==1){
cout<<1<<"\n";
cout<<1<<" "<<1<<"\n";
}
else
{
for(int i=2;i<=n;i++)
{
matrix[i][0]=1;
for(int j=1;j<=i;j++)
{
matrix[i][j]=matrix[i-1][j-1]+matrix[i-1][j];
}
matrix[i][i]=1;
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<=i;j++)
{
cout<<matrix[i][j]<<" ";
}
cout<<endl;
}
}
cout<<endl;
}
return 0;
}