Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / Pract. 04 / Solutions
diff options
context:
space:
mode:
Commitca18d5d5c3bb300bc9a353feaffa35275ea7d12e (patch)
Author
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-11-14 18:28:26 +0200
Committer
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-11-14 18:28:26 +0200
Files42986320a71b7cc4e5e76b76fdef721a3b5e9ce8 /pract_SI/Pract. 04/Solutions
Introduction_to_programming_FMI-ca18d5d5c3bb300bc9a353feaffa35275ea7d12e.tar
Introduction_to_programming_FMI-ca18d5d5c3bb300bc9a353feaffa35275ea7d12e.tar.gz
Introduction_to_programming_FMI-ca18d5d5c3bb300bc9a353feaffa35275ea7d12e.zip
Parentc92c14129dbefd34369186019450ead60a8183bb (diff)
Added Solutions Pract.04
diff --git a/pract_SI/Pract. 04/Solutions/task4 - abs.cpp b/pract_SI/Pract. 04/Solutions/task4 - abs.cpp
new file mode 100644
index 0000000..771550b
--- /dev/null
+++ b/pract_SI/Pract. 04/Solutions/task4 - abs.cpp
@@ -0,0 +1,4 @@
+int abs(int num1, int num2)
+{
+ return ((num1 - num2) >= 0 ? (num1 - num2) : (num2 - num1));
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 04/Solutions/task4 - fabs.cpp b/pract_SI/Pract. 04/Solutions/task4 - fabs.cpp
new file mode 100644
index 0000000..bb2f15b
--- /dev/null
+++ b/pract_SI/Pract. 04/Solutions/task4 - fabs.cpp
@@ -0,0 +1,4 @@
+double fabs(double &num)
+{
+ return num > 0.0 ? num : -num;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 04/Solutions/task7 - a).cpp b/pract_SI/Pract. 04/Solutions/task7 - a).cpp
new file mode 100644
index 0000000..8a590b4
--- /dev/null
+++ b/pract_SI/Pract. 04/Solutions/task7 - a).cpp
@@ -0,0 +1,3 @@
+bool isInInterval(int num) {
+ return num >= 100 && num <= 10000;
+}
diff --git a/pract_SI/Pract. 04/Solutions/task7 - b).cpp b/pract_SI/Pract. 04/Solutions/task7 - b).cpp
new file mode 100644
index 0000000..4dde747
--- /dev/null
+++ b/pract_SI/Pract. 04/Solutions/task7 - b).cpp
@@ -0,0 +1,3 @@
+bool isNumberInInterval(long longnum, long long interval_lower_bound, long long interval_upper_bound,) {
+ return num >= interval_lower_bound && num <= interval_upper_bound;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 04/Solutions/task8.cpp b/pract_SI/Pract. 04/Solutions/task8.cpp
new file mode 100644
index 0000000..9d91c6a
--- /dev/null
+++ b/pract_SI/Pract. 04/Solutions/task8.cpp
@@ -0,0 +1,9 @@
+long long pow(int num, unsigned N)
+{
+ long long result = 1;
+
+ for (size_t i = 0; i < N; i++)
+ result *= num;
+
+ return result;
+} \ No newline at end of file
diff --git a/pract_SI/Pract. 04/Solutions/task9.cpp b/pract_SI/Pract. 04/Solutions/task9.cpp
new file mode 100644
index 0000000..0356de8
--- /dev/null
+++ b/pract_SI/Pract. 04/Solutions/task9.cpp
@@ -0,0 +1,17 @@
+int calculate(int a, int b, char action = '+')
+{
+ switch (action)
+ {
+ case '+': return a + b;
+
+ case '-': return a - b;
+
+ case '*': return a * b;
+
+ case '/': return a / b;
+
+ case '%': return a % b;
+
+ default: return -1;
+ }
+} \ No newline at end of file