Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit616692d1e3605bbc77754c90434b82eb6b41c1d8 (patch)
Author
 Kristian Todorov <63777932+kristian3551@users.noreply.github.com>
2021-10-28 16:45:14 +0300
Committer
 Kristian Todorov <63777932+kristian3551@users.noreply.github.com>
2021-10-28 16:45:14 +0300
Filesf2aaa3a9ed2e015c2a8c5a478eaea73a3e967925
Introduction_to_programming_FMI-616692d1e3605bbc77754c90434b82eb6b41c1d8.tar
Introduction_to_programming_FMI-616692d1e3605bbc77754c90434b82eb6b41c1d8.tar.gz
Introduction_to_programming_FMI-616692d1e3605bbc77754c90434b82eb6b41c1d8.zip
Parent60a7ef49992dfb77c2ee3b8d02c56be582e72100 (diff)
solved ex 8 and 9 from sem. 3
3 files changed, 46 insertions, 32 deletions
-rw-r--r--Sem. 03/exercise 9 - rightmost pyramid.cpp24
-rw-r--r--Sem. 03/solutions/exercise 8 - dollar pyramid.cpp (renamed from Sem. 03/exercise 8 - dollar pyramid.cpp)18
-rw-r--r--Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp36
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 <iostream>
-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/exercise 8 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp
index e32c5ba..65f6106 100644
--- a/Sem. 03/exercise 8 - dollar pyramid.cpp
+++ b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp
@@ -1,17 +1,19 @@
#include <iostream>
using namespace std;
-void printPyramid(int n) {
- for(int i = 1; i <= n; i++) {
+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;
}
-}
-
-int main() {
- int n;
- cin >> n;
- printPyramid(n);
+
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 <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; 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