Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 03 / 14. Tree.cpp
diff options
context:
space:
mode:
1 files changed, 30 insertions, 0 deletions
-rw-r--r--Year 1/Programming introduction/Solutions Sem. 03/14. Tree.cpp30
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 <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);
+
+ cout << endl;
+ }
+
+ // Tree trunk
+ for (int row = n - 1; row > 0; row--)
+ {
+ for (int col = n - 1; col > 0; col--)
+ cout << " ";
+
+ cout << row << endl;
+ }
+}