From ca18d5d5c3bb300bc9a353feaffa35275ea7d12e Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Sun, 14 Nov 2021 18:28:26 +0200 Subject: Added Solutions Pract.04 --- pract_SI/Pract. 04/Solutions/task4 - abs.cpp | 4 ++++ pract_SI/Pract. 04/Solutions/task4 - fabs.cpp | 4 ++++ pract_SI/Pract. 04/Solutions/task7 - a).cpp | 3 +++ pract_SI/Pract. 04/Solutions/task7 - b).cpp | 3 +++ pract_SI/Pract. 04/Solutions/task8.cpp | 9 +++++++++ pract_SI/Pract. 04/Solutions/task9.cpp | 17 +++++++++++++++++ 6 files changed, 40 insertions(+) create mode 100644 pract_SI/Pract. 04/Solutions/task4 - abs.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task4 - fabs.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task7 - a).cpp create mode 100644 pract_SI/Pract. 04/Solutions/task7 - b).cpp create mode 100644 pract_SI/Pract. 04/Solutions/task8.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task9.cpp (limited to 'pract_SI/Pract. 04/Solutions') 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 -- cgit v1.3.1-23-gd82d