From 60a7ef49992dfb77c2ee3b8d02c56be582e72100 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 16:13:58 +0300 Subject: solved ex 8 and 9 from sem. 3 --- Sem. 03/exercise 8 - dollar pyramid.cpp | 17 +++++++++++++++++ Sem. 03/exercise 9 - rightmost pyramid.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Sem. 03/exercise 8 - dollar pyramid.cpp create mode 100644 Sem. 03/exercise 9 - rightmost pyramid.cpp diff --git a/Sem. 03/exercise 8 - dollar pyramid.cpp b/Sem. 03/exercise 8 - dollar pyramid.cpp new file mode 100644 index 0000000..e32c5ba --- /dev/null +++ b/Sem. 03/exercise 8 - dollar pyramid.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +void printPyramid(int n) { + for(int i = 1; i <= n; i++) { + for(int j = 1; j <= i; j++) + cout << "$" << " "; // print as many dollars as the number of the current row + cout << endl; + } +} + +int main() { + int n; + cin >> n; + printPyramid(n); + return 0; +} \ No newline at end of file diff --git a/Sem. 03/exercise 9 - rightmost pyramid.cpp b/Sem. 03/exercise 9 - rightmost pyramid.cpp new file mode 100644 index 0000000..f966fa2 --- /dev/null +++ b/Sem. 03/exercise 9 - rightmost pyramid.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +void printRightmostPyramid(int n) { + // print the first part of the pyramid (the one going from 1 to n(n-1)...21) + for(int i = 1; i <= n; i++) { + for(int k = n - i; k >= 0; k--) cout << " "; // print the spaces + for(int j = i; j >= 1; j--) cout << j; // print numbers j(j - 1)...21 + cout << endl; + } + // print the first part of the pyramid (the one going from (n-1)...21 to 1 + for(int i = n - 1; i >= 1; i--) { + for(int k = n - i; k >= 0; k--) cout << " "; + for(int j = i; j >= 1; j--) cout << j; + cout << endl; + } +} + +int main() { + int n; + cin >> n; + printRightmostPyramid(n); + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 616692d1e3605bbc77754c90434b82eb6b41c1d8 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 16:45:14 +0300 Subject: solved ex 8 and 9 from sem. 3 --- Sem. 03/exercise 8 - dollar pyramid.cpp | 17 ---------- Sem. 03/exercise 9 - rightmost pyramid.cpp | 24 --------------- Sem. 03/solutions/exercise 8 - dollar pyramid.cpp | 19 ++++++++++++ .../solutions/exercise 9 - rightmost pyramid.cpp | 36 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 41 deletions(-) delete mode 100644 Sem. 03/exercise 8 - dollar pyramid.cpp delete mode 100644 Sem. 03/exercise 9 - rightmost pyramid.cpp create mode 100644 Sem. 03/solutions/exercise 8 - dollar pyramid.cpp create mode 100644 Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp diff --git a/Sem. 03/exercise 8 - dollar pyramid.cpp b/Sem. 03/exercise 8 - dollar pyramid.cpp deleted file mode 100644 index e32c5ba..0000000 --- a/Sem. 03/exercise 8 - dollar pyramid.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -using namespace std; - -void printPyramid(int n) { - for(int i = 1; i <= n; i++) { - for(int j = 1; j <= i; j++) - cout << "$" << " "; // print as many dollars as the number of the current row - cout << endl; - } -} - -int main() { - int n; - cin >> n; - printPyramid(n); - return 0; -} \ No newline at end of file diff --git a/Sem. 03/exercise 9 - rightmost pyramid.cpp b/Sem. 03/exercise 9 - rightmost pyramid.cpp deleted file mode 100644 index f966fa2..0000000 --- a/Sem. 03/exercise 9 - rightmost pyramid.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -using namespace std; - -void printRightmostPyramid(int n) { - // print the first part of the pyramid (the one going from 1 to n(n-1)...21) - for(int i = 1; i <= n; i++) { - for(int k = n - i; k >= 0; k--) cout << " "; // print the spaces - for(int j = i; j >= 1; j--) cout << j; // print numbers j(j - 1)...21 - cout << endl; - } - // print the first part of the pyramid (the one going from (n-1)...21 to 1 - for(int i = n - 1; i >= 1; i--) { - for(int k = n - i; k >= 0; k--) cout << " "; - for(int j = i; j >= 1; j--) cout << j; - cout << endl; - } -} - -int main() { - int n; - cin >> n; - printRightmostPyramid(n); - return 0; -} \ No newline at end of file diff --git a/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp new file mode 100644 index 0000000..65f6106 --- /dev/null +++ b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + + int n; + cin >> n; + + for(int i = 1; i <= n; i++) + { + for(int j = 1; j <= i; j++) + cout << "$" << " "; // print as many dollars as the number of the current row + + cout << endl; + } + + return 0; +} \ No newline at end of file diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp new file mode 100644 index 0000000..80408ac --- /dev/null +++ b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +int main() +{ + + int n; + cin >> n; + + // print the first part of the pyramid (the one going from 1 to n(n-1)...21) + + for(int i = 1; i <= n; i++) + { + for(int k = n - i; k >= 0; k--) + cout << " "; // print the spaces + + for(int j = i; j >= 1; j--) + cout << j; // print numbers j(j - 1)...21 + + cout << endl; + } + // print the first part of the pyramid (the one going from (n-1)...21 to 1 + + for(int i = n - 1; i >= 1; i--) + { + for(int k = n - i; k >= 0; k--) + cout << " "; + + for(int j = i; j >= 1; j--) + cout << j; + + cout << endl; + } + + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 2f718a73d9226759f98d7d631f0d43ba180c5919 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:04:06 +0300 Subject: fixed styling and removed functions --- Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp index 80408ac..e95fa25 100644 --- a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp +++ b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp @@ -19,7 +19,7 @@ int main() cout << endl; } - // print the first part of the pyramid (the one going from (n-1)...21 to 1 + // print the second part of the pyramid (the one going from (n-1)...21 to 1 for(int i = n - 1; i >= 1; i--) { -- cgit v1.3.1-23-gd82d From 0901d0e587a4fd820d54dac9dca9477dff3b8670 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:07:57 +0300 Subject: fixed styling and spacing of ex 9 --- Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp index e95fa25..d1b339a 100644 --- a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp +++ b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp @@ -11,7 +11,7 @@ int main() for(int i = 1; i <= n; i++) { - for(int k = n - i; k >= 0; k--) + for(int k = n - i - 1; k >= 0; k--) cout << " "; // print the spaces for(int j = i; j >= 1; j--) @@ -23,7 +23,7 @@ int main() for(int i = n - 1; i >= 1; i--) { - for(int k = n - i; k >= 0; k--) + for(int k = n - i - 1; k >= 0; k--) cout << " "; for(int j = i; j >= 1; j--) -- cgit v1.3.1-23-gd82d