Uses Crt; const n=5; m=7; type Mas = array [1..n, 1..m] of integer; var i, j, j1, j2: integer; Sumj1, Sumj2: real; A: Mas; begin ClrScr; Randomize; SumJ1:=0; SumJ2:=0; for i:=1 to n do for j:=1 to m do A[i,j]:=random (10); WriteLn (' Massiv A: '); for i:=1 to n do begin for j:=1 to m do Write (A[i,j]:4); WriteLn; end; WriteLn; repeat Write (' Stolbez #1 = '); ReadLn(j1); until (j1>=1) and (j1<=m); repeat Write (' Stolbez #2 = '); ReadLn(j2); until (j2>=1) and (j2<=m) and (j1<>j2); for i:= 1 to n do SumJ1 := SumJ1+A[i,j1]; for i:= 1 to n do SumJ2:=SumJ2+A[i,j2]; SumJ1:=SumJ1/n; SumJ2:=SumJ2/n; WriteLn; WriteLn (' Srednee stolbza ', j1, ' = ', SumJ1:4:2); WriteLn (' Srednee stolbza ', j2, ' = ', SumJ2:4:2); ReadLn; end.
//PascalABC.Net 3.0, сборка 1064 type IntArray = array of integer;
var rows, cols: integer; M: array of IntArray;
begin Write('Количество строк и столбцов матрицы: '); Read(rows, cols); var Avg: array of double := new double[cols]; M := new IntArray[rows]; SetLength(Avg, cols); for var i := 0 to rows - 1 do begin M[i] := ArrRandom(cols, -25, 25); M[i].Println(#9) end; for var j := 0 to cols - 1 do Avg[j] := Range(0, rows - 1).Select(x -> M[x, j]).Average; Writeln('Наименьшее среднее по столбцам равно ', Avg.Min) end.
const n=5; m=7;
type Mas = array [1..n, 1..m] of integer;
var i, j, j1, j2: integer;
Sumj1, Sumj2: real;
A: Mas;
begin
ClrScr;
Randomize;
SumJ1:=0; SumJ2:=0;
for i:=1 to n do
for j:=1 to m do
A[i,j]:=random (10);
WriteLn (' Massiv A: ');
for i:=1 to n do
begin
for j:=1 to m do
Write (A[i,j]:4);
WriteLn;
end; WriteLn;
repeat
Write (' Stolbez #1 = '); ReadLn(j1);
until (j1>=1) and (j1<=m);
repeat
Write (' Stolbez #2 = '); ReadLn(j2);
until (j2>=1) and (j2<=m) and (j1<>j2);
for i:= 1 to n do
SumJ1 := SumJ1+A[i,j1];
for i:= 1 to n do
SumJ2:=SumJ2+A[i,j2];
SumJ1:=SumJ1/n; SumJ2:=SumJ2/n;
WriteLn;
WriteLn (' Srednee stolbza ', j1, ' = ', SumJ1:4:2);
WriteLn (' Srednee stolbza ', j2, ' = ', SumJ2:4:2);
ReadLn;
end.
type
IntArray = array of integer;
var
rows, cols: integer;
M: array of IntArray;
begin
Write('Количество строк и столбцов матрицы: '); Read(rows, cols);
var Avg: array of double := new double[cols];
M := new IntArray[rows];
SetLength(Avg, cols);
for var i := 0 to rows - 1 do
begin
M[i] := ArrRandom(cols, -25, 25);
M[i].Println(#9)
end;
for var j := 0 to cols - 1 do
Avg[j] := Range(0, rows - 1).Select(x -> M[x, j]).Average;
Writeln('Наименьшее среднее по столбцам равно ', Avg.Min)
end.
Тестовое решение:
Количество строк и столбцов матрицы: 5 8
-22 -8 12 7 3 -18 8 22
2 -16 17 -13 -10 0 -19 2
20 -21 -6 13 2 -20 25 24
-7 -3 -2 -10 -2 8 18 23
4 -21 -8 8 23 -12 -13 -5
Наименьшее среднее по столбцам равно -13.8