From 7e7c710287f25b9c958c9026b18f88587174d47f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 5 Jan 2024 08:59:38 +0200 Subject: [w11] Added solutions --- week11/ex2.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 week11/ex2.cpp (limited to 'week11/ex2.cpp') diff --git a/week11/ex2.cpp b/week11/ex2.cpp new file mode 100644 index 0000000..b4cac7b --- /dev/null +++ b/week11/ex2.cpp @@ -0,0 +1,44 @@ +#include + +// а) подточка +void printCharNTimes(int n, char c) { + for (int i = 0; i < n; i++) { + std::cout << c; + } + std::cout << std::endl; +} + +void triangleA(const int N, int current = 1) { + if (current > N) return; + + printCharNTimes(current, '+'); + + triangleA(N, current + 1); +} + +// б) подточка +void triangleB(const int N, int current = 1) { + if (current > N) return; + + triangleA(N, current + 1); + + printCharNTimes(current, '+'); +} + + +// в) подточка +void triangleC(const int N, int current = 1) { + if (current > N) return; + + printCharNTimes(current, '+'); + + triangleC(N, current + 1); + + printCharNTimes(current, '#'); +} + +int main() { + int N; + std::cin >> N; + triangleC(N); +} -- cgit v1.2.3