Вопрос задан 04.05.2019 в 22:28. Предмет Информатика. Спрашивает Солдатова Варя.

Дан массив 7×7 гсч (-5,5) если один элемент строки равен 0 то заменить все элементы на 0

0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Бутаев Вадим.
Const n=7;
var a: array [1..n,1..n] of integer;
    i,j,k:integer;
begin
for i:=1 to n do begin
  for j:=1 to n do begin
    a[i,j]:=-5+random(11);
    write(a[i,j],' ');
    end;
    writeln;
end;

for i:=1 to n do begin
  for j:=1 to n do begin
    if a[i,j]=0 then begin
      for k:=1 to n do
        a[k,j]:=0;
    end;
  end;
end;

writeln('=======================================');
for i:=1 to n do begin
  for j:=1 to n do begin
    write(a[i,j]:2,' ');
    end;
    writeln;
end;
end.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Task:

The task is to modify a 7x7 array of integers. If any element in a row is equal to 0, then all the elements in that row should be replaced with 0.

Solution:

To solve this problem, we can iterate through each row of the array and check if it contains a 0. If it does, we will set all the elements in that row to 0.

Here's a Python code snippet to achieve this:

```python # Given 7x7 array array = [ [1, 2, 3, 4, 5, 6, 7], [0, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, 32, 33, 34], [35, 36, 37, 38, 39, 40, 41], [42, 43, 44, 45, 46, 47, 48] ]

# Iterate through each row for row in array: if 0 in row: # Set all elements in the row to 0 row = [0] * 7

# Updated array print(array) ```

This code iterates through each row of the array and checks if it contains a 0. If it does, it sets all the elements in that row to 0.

Explanation:

The given array is iterated through row by row. If a row contains a 0, all the elements in that row are set to 0. This ensures that if any element in a row is equal to 0, all the elements in that row will be replaced with 0.

Please let me know if you need further assistance or clarification!

0 0

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

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

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