
Дано два одновимірні масиви, які складаються не більш як з 30 елементів кожний. Використавши
підпрограму пошуку максимального елемента, знайти півсуму максимальних елементів заданих масивів. програма мовою с++

Ответы на вопрос

Для поиска максимального элемента была написана функция findMax().
Хром жрет переносы строк, так что сейчас поправлю
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#include <iostream>
#include <string>
using namespace std;
int findMax(int *arr, int N)
{ int max = arr[0];
for (int i = 1; i < N; ++i)
if (arr[i] > max)
max = arr[i];
return max;
}
int main()
{
setlocale(LC_ALL, "Russian");
const int N = 30; int a[N], b[N];
cout << "A|B" << endl;
for (int i = 0; i < N; ++i){
a[i] = 1 + rand() % 9;
b[i] = 1 + rand() % 9;
cout << a[i] << "|" << b[i] << endl;
}
cout << endl << "Сумма: " << findMax(a, N) + findMax(b, N) << endl;
system("pause");
return 0;
}



To find the semi-sum of the maximum elements in two given one-dimensional arrays, you can follow these steps in the C++ programming language:
1. Declare and initialize two arrays with a maximum of 30 elements each. 2. Write a function to find the maximum element in an array. This function will take the array as a parameter and return the maximum element. 3. In the main function, call the maximum element function for both arrays and store the maximum elements in separate variables. 4. Calculate the semi-sum of the maximum elements by adding the two variables together and dividing the result by 2. 5. Print the semi-sum.
Here's an example code snippet that demonstrates this:
```cpp
#include
// Function to find the maximum element in an array int findMaxElement(int arr[], int size) { int maxElement = arr[0]; for (int i = 1; i < size; i++) { if (arr[i] > maxElement) { maxElement = arr[i]; } } return maxElement; }
int main() { int array1[30] = {1, 2, 3, 4, 5}; // Replace with your own array elements int array2[30] = {6, 7, 8, 9, 10}; // Replace with your own array elements
int maxElement1 = findMaxElement(array1, 5); // Replace '5' with the actual size of array1 int maxElement2 = findMaxElement(array2, 5); // Replace '5' with the actual size of array2
int semiSum = (maxElement1 + maxElement2) / 2;
std::cout << "Semi-sum of the maximum elements: " << semiSum << std::endl;
return 0; } ```
Please note that in the above code, I have assumed the size of both arrays to be 5 for simplicity. You should replace the array elements and adjust the size accordingly for your specific case.
I hope this helps! Let me know if you have any further questions.


Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili