From dbdce2c71e8327d5cbfa3e87840866b504efec0f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 5 Jan 2024 08:21:16 +0200 Subject: [w10] Added solutions --- week10/ex3.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 week10/ex3.cpp (limited to 'week10/ex3.cpp') diff --git a/week10/ex3.cpp b/week10/ex3.cpp new file mode 100644 index 0000000..1edf55d --- /dev/null +++ b/week10/ex3.cpp @@ -0,0 +1,27 @@ +#include + +void printCharNTimes(int n, char c) { + for (int i = 0; i < n; i++) { + std::cout << c; + } +} + +void hourglass(int lines, int whitespaces, int nonwhitespace) { + if (lines == 0) return; + + printCharNTimes(whitespaces, ' '); + printCharNTimes(nonwhitespace, '+'); + std::cout << std::endl; + + hourglass(lines - 1, whitespaces + 1, nonwhitespace - 2); + + printCharNTimes(whitespaces, ' '); + printCharNTimes(nonwhitespace, '#'); + std::cout << std::endl; +} + +int main() { + int N; + std::cin >> N; + hourglass(N, 0, 2*N - 1); +} -- cgit v1.2.3