Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / solutions
diff options
context:
space:
mode:
Commit72eb06dcc769114c7dbdcf7092e218b58d2196bf (patch)
Author
 Kamen Mladenov <kamen.d.mladenov@protonmail.com>
2021-11-03 19:39:06 +0200
Committer
 GitHub <noreply@github.com>
2021-11-03 19:39:06 +0200
Files452ee4354c0cd3edac025f81be477fd3f4268916 /Sem. 03/solutions
Introduction_to_programming_FMI-72eb06dcc769114c7dbdcf7092e218b58d2196bf.tar
Introduction_to_programming_FMI-72eb06dcc769114c7dbdcf7092e218b58d2196bf.tar.gz
Introduction_to_programming_FMI-72eb06dcc769114c7dbdcf7092e218b58d2196bf.zip
Parentd0071de8895c62003670e95421b5bc11185e69a9 (diff)
Parent91c58192153aec6803de90951e2d72b36fcc4e16 (diff)
Merge branch 'Angeld55:main' into sem03-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 <iostream>
+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 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 <iostream>
+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 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 <iostream>
+
+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;
+ }
+}
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 <iostream>
+
+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;
+ }
+}
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 <iostream>
+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;
+
+ }
+
+
+}