diff options
Added Solutions Pract.04
6 files changed, 40 insertions, 0 deletions
| -rw-r--r-- | pract_SI/Pract. 04/Solutions/task4 - abs.cpp | 4 | ||||
| -rw-r--r-- | pract_SI/Pract. 04/Solutions/task4 - fabs.cpp | 4 | ||||
| -rw-r--r-- | pract_SI/Pract. 04/Solutions/task7 - a).cpp | 3 | ||||
| -rw-r--r-- | pract_SI/Pract. 04/Solutions/task7 - b).cpp | 3 | ||||
| -rw-r--r-- | pract_SI/Pract. 04/Solutions/task8.cpp | 9 | ||||
| -rw-r--r-- | pract_SI/Pract. 04/Solutions/task9.cpp | 17 |
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 |
