Вопрос задан 01.05.2019 в 12:08. Предмет Информатика. Спрашивает Дацюк Рома.

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

підпрограму пошуку максимального елемента, знайти півсуму максимальних елементів заданих масивів. програма мовою с++
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Grigoryan Erik.
Массив задается внутри программно и инициализируется случайными числами от 1 до 9. (Тем не менее они всегда постоянны, так как не использован srand(...))
Для поиска максимального элемента была написана функция 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;
}
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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.

0 0

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

Последние заданные вопросы в категории Информатика

Задать вопрос