diff options
Solved newly added exercise 15
1 files changed, 34 insertions, 0 deletions
| -rw-r--r-- | Year 1/Programming introduction/Solutions Sem. 03/15. Bowtie.cpp | 34 |
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; + } +} |
