type Matrix = array[1..ROWS, 1..COLS] of Integer; AverageArray = array[1..ROWS] of Real;
procedure CalculateAverage(matrix: Matrix; var averages: AverageArray); var i, j: Integer; begin for i := 1 to ROWS do begin averages[i] := 0; for j := 1 to COLS do begin averages[i] := averages[i] + matrix[i, j]; end; averages[i] := averages[i] / COLS; end; end;
var matrix: Matrix; averages: AverageArray; i: Integer;
begin randomize;
// Заполнение массива случайными значениями for i := 1 to ROWS do begin for j := 1 to COLS do begin matrix[i, j] := random(10); write(matrix[i, j]:5); end; writeln; end;
CalculateAverage(matrix, averages);
writeln('Средние значения в каждой строке:'); for i := 1 to ROWS do begin writeln('Row ', i, ': ', averages[i]:0:2); end; end.
program AverageInRows;
const
ROWS = 5;
COLS = 6;
type
Matrix = array[1..ROWS, 1..COLS] of Integer;
AverageArray = array[1..ROWS] of Real;
procedure CalculateAverage(matrix: Matrix; var averages: AverageArray);
var
i, j: Integer;
begin
for i := 1 to ROWS do
begin
averages[i] := 0;
for j := 1 to COLS do
begin
averages[i] := averages[i] + matrix[i, j];
end;
averages[i] := averages[i] / COLS;
end;
end;
var
matrix: Matrix;
averages: AverageArray;
i: Integer;
begin
randomize;
// Заполнение массива случайными значениями
for i := 1 to ROWS do
begin
for j := 1 to COLS do
begin
matrix[i, j] := random(10);
write(matrix[i, j]:5);
end;
writeln;
end;
CalculateAverage(matrix, averages);
writeln('Средние значения в каждой строке:');
for i := 1 to ROWS do
begin
writeln('Row ', i, ': ', averages[i]:0:2);
end;
end.