uses
crt;
const
m=5; n=7;
type
realm = array[1..n] of real;
var
mA: array[1..m] of realm;
mS: array[1..n] of real;
tr: boolean;
e, v: integer; rr, tt: integer;
procedure fill_matrix(var mF: array of realm;ll, mm: integer);
var
l, m: integer;
begin
randomize;
for l:=1 to ll do begin
for m:=1 to mm do
begin
mF[l, m]:=random(300)-150;
end; end;
end;
function suma_el_st(mT: array of realm;i, j: integer): real;
var
k: integer;
suma: real;
begin
suma:=0;
for k:=1 to i do
suma:=suma+mT[k, j];
suma_el_st:=suma;
end;
procedure perestanovka_st(mP: array of realm; x, y: integer);
var
f: integer;
begin
for f:=1 to m do
begin
mP[x, f]:=mP[x, f]+mP[y, f];
mP[y, f]:=mP[x, f]-mP[y, f];
mP[x, f]:=mP[x, f]-mP[y, f];
end;
end;
begin
fill_matrix(mA, m, n);
{sort}
repeat
tr:=true;
for e:=1 to n-1 do begin
if suma_el_st(mA, e, n) < suma_el_st(mA, e, n+1) then begin
perestanovka_st(mA, n, n+1);
tr:=false;
end;
end;
until tr;
for rr:=1 to n do begin
for tt:=1 to m do
begin
write(mA[rr, tt]);
end;
writeln;
end;
end.
Матрица, Сортировка по суме элементов столбцов |