Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commited07ca36f9b87410838d6657eefd6ee9db686baa (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 17:24:40 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 17:24:40 +0200
Filesaceb62e97b9dd03bd75f69939ca87056318e8ac1
uni-projects-ed07ca36f9b87410838d6657eefd6ee9db686baa.tar
uni-projects-ed07ca36f9b87410838d6657eefd6ee9db686baa.tar.gz
uni-projects-ed07ca36f9b87410838d6657eefd6ee9db686baa.zip
Parent2961305814f60c9acdcc82a0f67fe6553c2e0b88 (diff)
Solved newly added exercise 15
1 files changed, 34 insertions, 0 deletions
-rw-r--r--Year 1/Programming introduction/Solutions Sem. 03/15. Bowtie.cpp34
diff --git a/Year 1/Programming introduction/Solutions Sem. 03/15. Bowtie.cpp b/Year 1/Programming introduction/Solutions Sem. 03/15. Bowtie.cpp
new file mode 100644
index 0000000..e06ab7e
--- /dev/null
+++ b/Year 1/Programming introduction/Solutions Sem. 03/15. Bowtie.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+
+using namespace std;
+
+int main() {
+ int n;
+ cin >> n;
+
+ char middleSpacer = ' ';
+ for(int i = -n + 1; i < n; i++)
+ {
+ int absI = (i < 0) ? -i : i, diff = n - absI;
+
+ /* Numbers on the left */
+ for(int j = 1; j <= diff; j++)
+ cout << j << " ";
+
+ /* Spaces/Line in the middle */
+ if (i == 0)
+ middleSpacer = '-';
+
+ for(int j = 5 * n - 4 * diff; j > 0; j--)
+ cout << middleSpacer;
+
+ if (i == 0)
+ middleSpacer = ' ';
+
+ /* Number on the right */
+ for(int j = diff; j > 0; j--)
+ cout << " " << j;
+
+ cout << endl;
+ }
+}