From a69cd34091836c632c3268e646ac5a85fb9f8175 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 29 Oct 2021 10:27:03 +0300 Subject: Added my solutions to Sem. 03 exercises --- .../Solutions Sem. 03/14. Tree.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Year 1/Programming introduction/Solutions Sem. 03/14. Tree.cpp (limited to 'Year 1/Programming introduction/Solutions Sem. 03/14. Tree.cpp') diff --git a/Year 1/Programming introduction/Solutions Sem. 03/14. Tree.cpp b/Year 1/Programming introduction/Solutions Sem. 03/14. Tree.cpp new file mode 100644 index 0000000..1955730 --- /dev/null +++ b/Year 1/Programming introduction/Solutions Sem. 03/14. Tree.cpp @@ -0,0 +1,30 @@ +#include + +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); + + cout << endl; + } + + // Tree trunk + for (int row = n - 1; row > 0; row--) + { + for (int col = n - 1; col > 0; col--) + cout << " "; + + cout << row << endl; + } +} -- cgit v1.3.1-26-gb76a