Вопрос задан 08.12.2023 в 03:44. Предмет Информатика. Спрашивает Соколова Ксюша.

Дан двухмерный массив. Определить :a.минимальный элемент пятой строки массива ;b.максимальный

элемент четвертого столбца массива. C++
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Солопатич Іван.

#include <iostream>

#include <vector>

#include <cstdlib>

using namespace std;

void a(vector<vector<int>> arr) {

unsigned long long int min = 18446744073709551615;

for(int i = 0; i<arr[4].size(); ++i) {

 if(arr[4][0]<min) {

  min = arr[4][0];

 }

}

cout << endl << "Min: " << min;

}

void b(vector<vector<int>> arr, int x, int y) {

int max = -1;

for(int i = 0; i<x; ++i) {

 if(arr[i][3]>max) {

  max = arr[i][3];

 }

}

cout << endl << "max: " << max;

}

int main() {

srand(123);

cout << "Array x*y. Enter x: ";

int x = 0;

cin >> x;

cout << "Enter y: ";

int y = 0;

cin >> y;

if(x<5||y<4) {

 cout << "Wrong data. x<5 or y<4";

 return 0;

}

vector<vector<int>> arr;

for(int i = 0; i<x; ++i) {

 vector<int> temp;

 temp.push_back(rand());

 arr.push_back(temp);

 for(int j = 0; j<y; ++j) {

  arr[i].push_back(rand());

 }

}

for(int i = 0; i<x; ++i) {

 for(int j = 0; j<x; ++j) {

  cout << arr[i][j] << " ";

  if(j==x-1) {

   cout << endl;

  }

 }

}

a(arr);

b(arr, x, y);

}

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Task:

Given a two-dimensional array, determine: a. the minimum element of the fifth row of the array. b. the maximum element of the fourth column of the array.

Solution:

To solve this problem, we can iterate through the array to find the minimum element of the fifth row and the maximum element of the fourth column.

Here's a sample C++ code to achieve this:

```cpp #include using namespace std;

int main() { int arr[5][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}, {17, 18, 19, 20} };

// Finding the minimum element of the fifth row int minFifthRow = arr[4][0]; for (int i = 1; i < 4; i++) { if (arr[4][i] < minFifthRow) { minFifthRow = arr[4][i]; } }

// Finding the maximum element of the fourth column int maxFourthColumn = arr[0][3]; for (int i = 1; i < 5; i++) { if (arr[i][3] > maxFourthColumn) { maxFourthColumn = arr[i][3]; } }

cout << "Minimum element of the fifth row: " << minFifthRow << endl; cout << "Maximum element of the fourth column: " << maxFourthColumn << endl;

return 0; } ```

This code initializes a 5x4 array and then iterates through the array to find the minimum element of the fifth row and the maximum element of the fourth column.

Note: The specific array values are not provided, so the code uses placeholder values for demonstration purposes.

Let me know if you need further assistance!

0 0

Похожие вопросы

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

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

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