Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / Solutions / 14. Tree.cpp
blob: f55d47d866cacaec715a547f51bb26d9d795dc2c (plain) (blame)
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
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;

	// Tree crown
	for (int row = 1; row <= n; row++)
	{
		for (int col = n - row; col > 0; col--)
			cout << " ";

		for (int col = -row + 1; col < row; col++)
			cout << row - ((col < 0) ? -col : col); // row - abs(col)

		cout << endl;
	}

	// Tree trunk
	for (int row = n - 1; row > 0; row--)
	{
		for (int col = n - 1; col > 0; col--)
			cout << " ";

		cout << row << endl;
	}
}