Вопрос задан 20.02.2019 в 16:57. Предмет Информатика. Спрашивает Фаттахудинова Ирина.

Дана матрица А (4*5). Вычислить сумму квадратов всех ее отрицательных элементов. Кто сможет решите

на паскале?
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Соколова Екатерина.
Const
  m=4;
  n=5;
var
  a:array[1..m,1..n] of integer;
  i,j,s,e:integer;
begin
  Randomize;
  s:=0;
  for i:=1 to m do
    begin
    for j:=1 to n do
      begin
      e:=Random(100)-50;
      a[i,j]:=e;
      if e<0 then s:=s+sqr(e);
      write(e:4)
      end;
    writeln
    end;
  writeln('Сумма квадратов отрицательных элементов равна ',s)
end.

Тестовое решение:

  43 -12 -47  27  34
 -47 -44 -38  47  -5
  29 -40 -44  46  21
 -17  32   0  10 -43
Сумма квадратов отрицательных элементов равна 13641


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

Calculating the Sum of Squares of Negative Elements in a Matrix

To calculate the sum of squares of all the negative elements in a given matrix A (4x5), we can follow these steps:

1. Identify the Negative Elements in the Matrix A: - Iterate through each element of the matrix and identify the negative elements.

2. Calculate the Sum of Squares of Negative Elements: - For each negative element, calculate its square and add it to the running sum.

3. Return the Final Sum: - The final sum obtained in the previous step will be the sum of squares of all the negative elements in the matrix.

Pascal Code for Calculating the Sum of Squares of Negative Elements

Here's a Pascal code snippet to calculate the sum of squares of negative elements in a given matrix A (4x5):

```pascal program SumOfSquares; var A: array[1..4, 1..5] of Integer; i, j, sum: Integer; begin sum := 0; { Initialize matrix A with values } { ... }

{ Calculate sum of squares of negative elements } for i := 1 to 4 do begin for j := 1 to 5 do begin if A[i, j] < 0 then sum := sum + A[i, j] * A[i, j]; end; end;

{ Display the final sum } writeln('The sum of squares of negative elements is: ', sum); end. ```

In this code, we initialize the matrix A with appropriate values and then iterate through each element to calculate the sum of squares of negative elements. The final sum is then displayed as the output.

Feel free to modify the code according to your specific matrix A values and test it in your Pascal environment.

Let me know if you need further assistance with this or any other topic!

0 0

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

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

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