Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise01.cpp
diff options
context:
space:
mode:
1 files changed, 37 insertions, 0 deletions
-rw-r--r--Week13/Exercise01.cpp37
diff --git a/Week13/Exercise01.cpp b/Week13/Exercise01.cpp
new file mode 100644
index 0000000..ed5797e
--- /dev/null
+++ b/Week13/Exercise01.cpp
@@ -0,0 +1,37 @@
+#include <iostream>
+
+void line(unsigned n) {
+ if (n == 0) {
+ std::cout << std::endl;
+ }
+ else {
+ std::cout << '+';
+ line(n - 1);
+ }
+}
+
+/* Два начина по които да имплементираме изкарването на "стълбите" */
+
+void stairs1(unsigned i, unsigned max) {
+ if (i <= max) {
+ line(i);
+ stairs1(i + 1, max);
+ }
+}
+
+void stairs2(unsigned n) {
+ if (n > 0) {
+ stairs2(n - 1);
+ line(n);
+ }
+}
+
+int main() {
+ unsigned n;
+ std::cin >> n;
+
+ // stairs1(1, n);
+ stairs2(n);
+
+ return 0;
+}