Created
March 20, 2025 17:33
-
-
Save vlaleli/e8b3949860eb35c8e5f96d29195c98e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cmath> | |
| // 1. Функція my_increment | |
| void my_increment(int* ptr, int n = 1) { | |
| if (ptr) { | |
| *ptr += n; | |
| } | |
| } | |
| // 2. Функція multiply | |
| void multiply(const int* a, const int* b, int* result) { | |
| if (a && b && result) { | |
| *result = (*a) * (*b); | |
| } | |
| } | |
| // 3. Функція negate | |
| void negate(double* num) { | |
| if (num) { | |
| *num = -(*num); | |
| } | |
| } | |
| // 4. Функція setValue | |
| void setValue(int* ptr, int newValue) { | |
| if (ptr) { | |
| *ptr = newValue; | |
| } | |
| } | |
| // 5. Функція concatenateDigits | |
| void concatenateDigits(const int* a, const int* b, int* result) { | |
| if (a && b && result) { | |
| int temp = *b; | |
| int digits = (temp == 0) ? 1 : (int)log10(temp) + 1; | |
| *result = (*a) * (int)pow(10, digits) + temp; | |
| } | |
| } | |
| int main() { | |
| int x = 5, y = 3, result; | |
| double num = -7.5; | |
| my_increment(&x); | |
| std::cout << "After increment: " << x << std::endl; | |
| multiply(&x, &y, &result); | |
| std::cout << "Multiplication result: " << result << std::endl; | |
| negate(&num); | |
| std::cout << "Negated number: " << num << std::endl; | |
| setValue(&x, 42); | |
| std::cout << "New value of x: " << x << std::endl; | |
| int a = 12, b = 34; | |
| concatenateDigits(&a, &b, &result); | |
| std::cout << "Concatenated digits: " << result << std::endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment