summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-08-16 19:00:04 +0200
committerOskar <[email protected]>2024-08-16 19:00:04 +0200
commitbfa29c55fd58912845b5a6684489231a4d4e675e (patch)
tree615213f43d685d7cc0b14cac0fcafe70cddb07e7
parent6ff70adb810f1e194892398656e71f979f088feb (diff)
more exercises
-rw-r--r--4p1.cpp1
-rw-r--r--4p4.cpp16
-rw-r--r--4p5.cpp32
-rw-r--r--4p6.cpp22
-rw-r--r--4p7.cpp25
-rw-r--r--exercise-template.cpp1
6 files changed, 95 insertions, 2 deletions
diff --git a/4p1.cpp b/4p1.cpp
index 38bc535..64d0973 100644
--- a/4p1.cpp
+++ b/4p1.cpp
@@ -1,5 +1,4 @@
#include <iostream>
-#include <vector>
/*
*
diff --git a/4p4.cpp b/4p4.cpp
new file mode 100644
index 0000000..d290a85
--- /dev/null
+++ b/4p4.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+
+/*
+ *
+ * 4.4
+ *
+ *
+ */
+
+int main () {
+
+ int res1 = ((((12 / 3) * 4) + (5 * 15)) + ((24 % 4) / 2));
+ int res2 = 12 / 3 * 4 + 5 * 15 + 24 % 4 / 2;
+ std::cout << res1 << " " << res2 << std::endl;
+ return 0;
+}
diff --git a/4p5.cpp b/4p5.cpp
new file mode 100644
index 0000000..abeefdd
--- /dev/null
+++ b/4p5.cpp
@@ -0,0 +1,32 @@
+#include <iostream>
+
+/*
+ *
+ * 4.5
+ *
+ *
+ */
+
+int main () {
+
+ int res_a = -30 * 3 + 21 / 5;
+ int res_b = -30 + 3 * 21 / 5;
+ int res_c = 30 / 3 * 21 % 5;
+ int res_d = -30 / 3 * 21 % 4;
+ int p_res_a = ((-30 * 3) + (21 / 5)); // -86
+ int p_res_b = (-30 + ((3 * 21) / 5)); // -18
+ int p_res_c = (((30 / 3) * 21) % 5); // 0
+ int p_res_d = (((-30 / 3) * 21) % 4); // -2
+
+ std::cout << res_a << "\n"
+ << res_b << "\n"
+ << res_c << "\n"
+ << res_d << "\n" << std::endl;
+
+ std::cout << p_res_a << "\n"
+ << p_res_b << "\n"
+ << p_res_c << "\n"
+ << p_res_d << "\n" << std::endl;
+
+ return 0;
+}
diff --git a/4p6.cpp b/4p6.cpp
new file mode 100644
index 0000000..e7465f6
--- /dev/null
+++ b/4p6.cpp
@@ -0,0 +1,22 @@
+#include <iostream>
+
+/*
+ *
+ * 4.6
+ *
+ *
+ */
+
+int main () {
+
+ int input;
+ if(std::cin >> input) {} else { return -1; }
+
+ if(input % 2 == 0) {
+ std::cout << "Even" << std::endl;
+ } else {
+ std::cout << "Odd" << std::endl;
+ }
+
+ return 0;
+}
diff --git a/4p7.cpp b/4p7.cpp
new file mode 100644
index 0000000..8ad9d2e
--- /dev/null
+++ b/4p7.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+#include <climits>
+
+/*
+ *
+ * 4.7
+ *
+ *
+ */
+
+int main () {
+
+ unsigned short int i = -1; // Underflow?
+ std::cout << i << " " << std::endl;
+ short int sii = 1;
+ short int si = SHRT_MAX + sii; // Overflow
+ std::cout << si << " " << std::endl;
+ unsigned short int usii = 1; // Overflow
+ unsigned short int usi = USHRT_MAX + usii;
+ std::cout << usi << " " << std::endl;
+ short int d = SHRT_MAX;
+ short int f = SHRT_MAX + d;
+ std::cout << f << " " << std::endl;
+ return 0;
+}
diff --git a/exercise-template.cpp b/exercise-template.cpp
index 0048d2b..58d5fbf 100644
--- a/exercise-template.cpp
+++ b/exercise-template.cpp
@@ -1,5 +1,4 @@
#include <iostream>
-#include <vector>
/*
*