Вопрос задан 14.02.2019 в 21:54. Предмет Информатика. Спрашивает Trushevska Nikoletta.

Найти наибольший элемент массива размером МхN, элементы которого задаются датчиком случайных чисел

на интервале [-25;19].
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Смирнов Евгений.
// PascalABC.NET 3.1, сборка 1213 от 04.04.2016
begin
  var m,n:integer;
  Write('Введите n и m: '); Read(n,m);
  var a:=MatrixRandom(n,m,-25,19);
  var max:=-26; // меньше возможного меньшего
  for var i:=0 to n-1 do begin
    for var j:=0 to m-1 do begin
      Write(a[i,j]:4);
      if a[i,j]>max then max:=a[i,j]
      end;
    Writeln
    end;
  Writeln('Максимальный элемент равен ',max)
end.

Тестовое решение:
Введите n и m: 5 8
 -25  -3 -20  -8  -4 -21   9 -16
   0  17   9 -22  10  15  -2  11
  -1  17 -12 -15   0  -7  17 -16
 -22  -9 -18   4  -4  -9   4 -16
  -8 -17 -21  11  -4  -7 -12  13
Максимальный элемент равен 17
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Finding the Largest Element in an MxN Array

To find the largest element in an array of size MxN, where the elements are generated by a random number generator within the interval [-25;19], you can use a simple algorithm to iterate through the array and keep track of the largest element found so far.

Here's a basic algorithm to achieve this:

1. Initialize a variable, let's call it `largest`, to a value smaller than the minimum possible value in the array (e.g., -26). 2. Iterate through each element in the MxN array. 3. For each element, compare it with the current value of `largest`. If the element is greater than `largest`, update `largest` to the value of the current element. 4. After iterating through all elements, the variable `largest` will hold the largest element in the array.

In pseudocode, this algorithm looks like:

``` largest = -26 // Initializing with a value smaller than the minimum possible value for i = 1 to M for j = 1 to N if array[i][j] > largest largest = array[i][j] ```

This algorithm ensures that `largest` will hold the largest element in the MxN array after the iteration.

Note: This is a basic algorithm. Depending on the programming language you are using, there may be more efficient ways to achieve this.

Let me know if you need further assistance with implementing this algorithm in a specific programming language!

0 0

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

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

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