Матрица размером 5:5 заполняется случайными числами, кроме главной диагонали.По главной диагонали пустить -1.Найти количество элементов,оканчивающихся на ноль,отрицательных элементов и нулей,сумму элементов побочной диагонали. ПАСКАЛЬ
// Fill the matrix and calculate required values for i := 1 to 5 do begin for j := 1 to 5 do begin if i = j then matrix[i, j] := -1 else matrix[i, j] := random(201) - 100;
if matrix[i, j] mod 10 = 0 then countZeroEnd := countZeroEnd + 1; if matrix[i, j] < 0 then countNegative := countNegative + 1; if matrix[i, j] = 0 then countZero := countZero + 1; if i + j = 6 then sumSideDiagonal := sumSideDiagonal + matrix[i, j]; end;
end;
// Output the matrix for i := 1 to 5 do begin for j := 1 to 5 do begin write(matrix[i, j]:5); end; writeln; end;
// Output results writeln; writeln('Number of elements ending with zero: ', countZeroEnd); writeln('Number of negative elements: ', countNegative); writeln('Number of zeros: ', countZero); writeln('Sum of elements on the side diagonal: ', sumSideDiagonal);
program MatrixOperations;
uses crt;
var
matrix: array[1..5, 1..5] of integer;
i, j, countZeroEnd, countNegative, countZero, sumSideDiagonal: integer;
begin
randomize;
countZeroEnd := 0;
countNegative := 0;
countZero := 0;
sumSideDiagonal := 0;
// Fill the matrix and calculate required values
if matrix[i, j] mod 10 = 0 thenfor i := 1 to 5 do
begin
for j := 1 to 5 do
begin
if i = j then
matrix[i, j] := -1
else
matrix[i, j] := random(201) - 100;
countZeroEnd := countZeroEnd + 1;
if matrix[i, j] < 0 then
countNegative := countNegative + 1;
if matrix[i, j] = 0 then
countZero := countZero + 1;
if i + j = 6 then
sumSideDiagonal := sumSideDiagonal + matrix[i, j];
end;
end;
// Output the matrix
for i := 1 to 5 do
begin
for j := 1 to 5 do
begin
write(matrix[i, j]:5);
end;
writeln;
end;
// Output results
writeln;
writeln('Number of elements ending with zero: ', countZeroEnd);
writeln('Number of negative elements: ', countNegative);
writeln('Number of zeros: ', countZero);
writeln('Sum of elements on the side diagonal: ', sumSideDiagonal);
end.