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/solutions/exercise 8 - dollar pyramid.cpp | 19 ++++++++++++ .../solutions/exercise 9 - rightmost pyramid.cpp | 36 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Sem. 03/solutions/exercise 8 - dollar pyramid.cpp create mode 100644 Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp (limited to 'Sem. 03/solutions') 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(-) (limited to 'Sem. 03/solutions') 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(-) (limited to 'Sem. 03/solutions') 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 From a78a314b374e5372c3865f16bde40845db5b79a2 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:51:13 -0400 Subject: Create exercise 10.cpp --- Sem. 03/solutions/exercise 10.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Sem. 03/solutions/exercise 10.cpp (limited to 'Sem. 03/solutions') diff --git a/Sem. 03/solutions/exercise 10.cpp b/Sem. 03/solutions/exercise 10.cpp new file mode 100644 index 0000000..dae43ab --- /dev/null +++ b/Sem. 03/solutions/exercise 10.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + for (int j = 0; j < count; j++) + { + if (j % 2 == 0) + { + cout << i + (count * j) << " "; + } + else + { + cout << (j + 1) * count - (i - 1) << " "; + } + } + cout << endl; + } +} -- cgit v1.3.1-23-gd82d From 235bbe2ccc3565f8af02f9cddd76b8937f6dff33 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:51:25 -0400 Subject: Rename exercise 8 - dollar pyramid.cpp to exercise 08 - dollar pyramid.cpp --- Sem. 03/solutions/exercise 08 - dollar pyramid.cpp | 19 +++++++++++++++++++ Sem. 03/solutions/exercise 8 - dollar pyramid.cpp | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 Sem. 03/solutions/exercise 08 - dollar pyramid.cpp delete mode 100644 Sem. 03/solutions/exercise 8 - dollar pyramid.cpp (limited to 'Sem. 03/solutions') diff --git a/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp new file mode 100644 index 0000000..1ea164d --- /dev/null +++ b/Sem. 03/solutions/exercise 08 - 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; +} diff --git a/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp deleted file mode 100644 index 65f6106..0000000 --- a/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#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 -- cgit v1.3.1-23-gd82d From 4eb49067c08480fa0b435e6969655e142b71600d Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:51:36 -0400 Subject: Rename exercise 9 - rightmost pyramid.cpp to exercise 09 - rightmost pyramid.cpp --- .../solutions/exercise 09 - rightmost pyramid.cpp | 36 ++++++++++++++++++++++ .../solutions/exercise 9 - rightmost pyramid.cpp | 36 ---------------------- 2 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp delete mode 100644 Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp (limited to 'Sem. 03/solutions') diff --git a/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp new file mode 100644 index 0000000..573b98b --- /dev/null +++ b/Sem. 03/solutions/exercise 09 - 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 - 1; 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 second 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 - 1; k >= 0; k--) + cout << " "; + + for(int j = i; j >= 1; j--) + cout << j; + + cout << endl; + } + + return 0; +} diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp deleted file mode 100644 index d1b339a..0000000 --- a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#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 - 1; 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 second 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 - 1; 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 c132894e81e29e4c6c6dfa3a2ea70aea95860955 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:52:11 -0400 Subject: Create exercise 11.cpp --- Sem. 03/solutions/exercise 11.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Sem. 03/solutions/exercise 11.cpp (limited to 'Sem. 03/solutions') diff --git a/Sem. 03/solutions/exercise 11.cpp b/Sem. 03/solutions/exercise 11.cpp new file mode 100644 index 0000000..66a90a9 --- /dev/null +++ b/Sem. 03/solutions/exercise 11.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + if (i % 2 != 0) + { + for (int j = 1 + ((i - 1) * count); j <= i * count; j++) + { + cout << j << " "; + } + } + else + { + for (int j = i * count; j > (i - 1) * count; j--) + { + cout << j << " "; + } + } + cout << endl; + } +} -- cgit v1.3.1-23-gd82d From 90d1e842ee65040064207e53bf204d4d9b32d547 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 18:19:49 +0200 Subject: Create exercise 15.cpp --- Sem. 03/solutions/exercise 15.cpp | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Sem. 03/solutions/exercise 15.cpp (limited to 'Sem. 03/solutions') diff --git a/Sem. 03/solutions/exercise 15.cpp b/Sem. 03/solutions/exercise 15.cpp new file mode 100644 index 0000000..652a201 --- /dev/null +++ b/Sem. 03/solutions/exercise 15.cpp @@ -0,0 +1,58 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + int spacesCount = 2 * (n - 1) + n + 2 * (n - 1); + int toGuess; + for (int i = 1; i <= n - 1; i++) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount -= 4; + + cout << endl; + + } + + //mid + for (int i = 1; i <= n; i++) + cout << i << " "; + for (int i = 0; i < n; i++) + cout << '-'; + for (int i = n; i >= 1; i--) + cout << " " << i; + cout << endl; + + + //down + spacesCount += 4; + for (int i = n - 1; i >= 0; i--) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount += 4; + + cout << endl; + + } + + +} -- cgit v1.3.1-23-gd82d