-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19.cpp
58 lines (53 loc) · 1.06 KB
/
19.cpp
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
/*
Problem Link: https://www.hackerearth.com/problem/algorithm/christmas-tree-of-height-n/
This year Santa wants to make a Christmas tree.
But this time he wants to decorate it with numbers as in the Pascal’s triangle.
But Santa is very busy in packing the gifts. Now, you being Santa’s friend help in making the tree.
Input:
In the first line, you will be given ”t” no. of test cases.
For each test case, you will be given a whole number “N”.
Output:
For each value N, Print the first N lines in Christmas tree.
Constraints:
1≤T≤100
1 ≤ N ≤ 40
Sample Input:
2
3
5
Sample Output:
1
1 1
1 2 1
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
long long int triangle[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
if(j==0 || j==i)
triangle[i][j]=1;
else
triangle[i][j]=triangle[i-1][j-1] + triangle[i-1][j];
cout<<triangle[i][j]<<" ";
}
cout<<endl;
}
}
return 0;
}