From 2b75c583cc64bdc16f619e9de7c4352121e069df Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 3 Nov 2021 17:23:02 +0200 Subject: Solved newly added exercise 15 --- Sem. 03/Solutions/15. Bowtie.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Sem. 03/Solutions/15. Bowtie.cpp diff --git a/Sem. 03/Solutions/15. Bowtie.cpp b/Sem. 03/Solutions/15. Bowtie.cpp new file mode 100644 index 0000000..e06ab7e --- /dev/null +++ b/Sem. 03/Solutions/15. Bowtie.cpp @@ -0,0 +1,34 @@ +#include + +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; + } +} -- cgit v1.3.1-23-gd82d