var f: array [1..k, 1..p] of byte; mini: array [1..2] of byte := (1, 1); maxi: array [1..2] of byte := (1, 1);
procedure Swap(var a, b: integer); var p: integer; begin p := a; a := b; b := p; end;
begin for i: byte := 1 to k do begin for j: byte := 1 to p do begin f[i, j] := random(10, 100); write(f[i, j]:3); if (f[mini[1], mini[2]] > f[i, j]) then begin mini[1] := i; mini[2] := j; end; if (f[maxi[1], maxi[2]] < f[i, j]) then begin maxi[1] := i; maxi[2] := j; end; end; writeln(); end; writeln();
var i, j, e, max, min: integer; F: array[1..k, 1..p] of integer;
begin Randomize; writeln('Исходная матрица'); max := -32768; min := 32767; for i := 1 to k do begin for j := 1 to p do begin e := random(100) - 50; if e > max then max := e else if e < min then min := e; write(e:4); F[i, j] := e end; writeln end; F[1, p] := max; F[k, 1] := min; writeln('Результирующая матрица'); for i := 1 to k do begin for j := 1 to p do write(F[i, j]:4); writeln end end.
k = 3;
p = 3;
var
f: array [1..k, 1..p] of byte;
mini: array [1..2] of byte := (1, 1);
maxi: array [1..2] of byte := (1, 1);
procedure Swap(var a, b: integer);
var
p: integer;
begin
p := a;
a := b;
b := p;
end;
begin
for i: byte := 1 to k do
begin
for j: byte := 1 to p do
begin
f[i, j] := random(10, 100);
write(f[i, j]:3);
if (f[mini[1], mini[2]] > f[i, j]) then
begin
mini[1] := i;
mini[2] := j;
end;
if (f[maxi[1], maxi[2]] < f[i, j]) then
begin
maxi[1] := i;
maxi[2] := j;
end;
end;
writeln();
end;
writeln();
swap(f[1, p], f[maxi[1], maxi[2]]);
swap(f[p, 1], f[mini[1], mini[2]]);
for i: byte := 1 to k do
begin
for j: byte := 1 to p do
write(f[i, j]:3);
writeln();
end;
end.
k = 7;
p = 10;
var
i, j, e, max, min: integer;
F: array[1..k, 1..p] of integer;
begin
Randomize;
writeln('Исходная матрица');
max := -32768;
min := 32767;
for i := 1 to k do
begin
for j := 1 to p do
begin
e := random(100) - 50;
if e > max then max := e
else if e < min then min := e;
write(e:4);
F[i, j] := e
end;
writeln
end;
F[1, p] := max;
F[k, 1] := min;
writeln('Результирующая матрица');
for i := 1 to k do
begin
for j := 1 to p do
write(F[i, j]:4);
writeln
end
end.
Тестовое решение:
Исходная матрица
34 36 41 9 -4 39 29 1 15 -33
13 -9 -29 28 -45 -1 8 38 37 12
-33 45 3 35 -47 -14 -30 49 -29 -6
-50 -49 42 15 46 4 24 -21 -10 23
-14 30 -14 -46 33 -26 24 2 -3 -31
-27 15 47 25 -43 39 -17 -44 6 -40
19 30 -20 -29 -34 12 -2 5 32 0
Результирующая матрица
34 36 41 9 -4 39 29 1 15 49
13 -9 -29 28 -45 -1 8 38 37 12
-33 45 3 35 -47 -14 -30 49 -29 -6
-50 -49 42 15 46 4 24 -21 -10 23
-14 30 -14 -46 33 -26 24 2 -3 -31
-27 15 47 25 -43 39 -17 -44 6 -40
-50 30 -20 -29 -34 12 -2 5 32 0