Created
March 27, 2025 15:39
-
-
Save vlaleli/a7e3923c0b94008f3dc9cead7e466fee 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
| 1) | |
| #include <iostream> | |
| void calculateSumAndProduct(int* arr, int size, int* sum, int* product) { | |
| *sum = 0; | |
| *product = 1; | |
| for (int i = 0; i < size; ++i) { | |
| *sum += arr[i]; | |
| *product *= arr[i]; | |
| } | |
| } | |
| int main() { | |
| int array[] = {1, 2, 3, 4, 5}; | |
| int size = sizeof(array) / sizeof(array[0]); | |
| int sum = 0, product = 0; | |
| calculateSumAndProduct(array, size, &sum, &product); | |
| std::cout << "Сума: " << sum << std::endl; | |
| std::cout << "Добуток: " << product << std::endl; | |
| return 0; | |
| } | |
| 2) | |
| #include <iostream> | |
| void countElements(int* arr, int size, int* negativeCount, int* positiveCount, int* zeroCount) { | |
| *negativeCount = 0; | |
| *positiveCount = 0; | |
| *zeroCount = 0; | |
| for (int i = 0; i < size; ++i) { | |
| if (arr[i] < 0) | |
| (*negativeCount)++; | |
| else if (arr[i] > 0) | |
| (*positiveCount)++; | |
| else | |
| (*zeroCount)++; | |
| } | |
| } | |
| int main() { | |
| int array[] = {3, -1, 0, 4, -5, 0, 2}; | |
| int size = sizeof(array) / sizeof(array[0]); | |
| int neg = 0, pos = 0, zero = 0; | |
| countElements(array, size, &neg, &pos, &zero); | |
| std::cout << "Кількість від'ємних: " << neg << std::endl; | |
| std::cout << "Кількість додатних: " << pos << std::endl; | |
| std::cout << "Кількість нульових: " << zero << std::endl; | |
| return 0; | |
| } | |
| 5) | |
| #include <iostream> | |
| int* appendBlock(int* array, int size, int* block, int blockSize, int* newSize) { | |
| *newSize = size + blockSize; | |
| int* newArray = new int[*newSize]; | |
| for (int i = 0; i < size; ++i) | |
| newArray[i] = array[i]; | |
| for (int i = 0; i < blockSize; ++i) | |
| newArray[size + i] = block[i]; | |
| return newArray; | |
| } | |
| int main() { | |
| int arr[] = {1, 2, 3}; | |
| int block[] = {4, 5, 6}; | |
| int newSize; | |
| int* result = appendBlock(arr, 3, block, 3, &newSize); | |
| std::cout << "Новий масив: "; | |
| for (int i = 0; i < newSize; ++i) | |
| std::cout << result[i] << " "; | |
| delete[] result; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment