aboutsummaryrefslogtreecommitdiff
path: root/week11/ex2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'week11/ex2.cpp')
-rw-r--r--week11/ex2.cpp44
1 files changed, 44 insertions, 0 deletions
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 <iostream>
+
+// а) подточка
+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);
+}