Const m=5; n=6; var a:array[1..m,1..n] of integer; i,j,max,imax,jmax,min,imin,jmin:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to m do begin for j:=1 to n do begin a[i,j]:=random(100); write(a[i,j]:4); end; writeln; end; max:=a[1,1]; imax:=1; jmax:=1; min:=a[1,1]; imin:=1; jmin:=1; for i:=1 to m do for j:=1 to n do begin if a[i,j]>max then begin max:=a[i,j]; imax:=i; jmax:=j; end; if a[i,j]<min then begin min:=a[i,j]; imin:=i; jmin:=j; end; end; writeln('max = a[',imax,',',jmax,'] = ',max); writeln('min = a[',imin,',',jmin,'] = ',min); a[imax,jmax]:=min; a[imin,jmin]:=max; writeln('Полученный массив:'); for i:=1 to m do begin for j:=1 to n do write(a[i,j]:4); writeln; end; end.
var
a:array[1..m,1..n] of integer;
i,j,max,imax,jmax,min,imin,jmin:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to m do
begin
for j:=1 to n do
begin
a[i,j]:=random(100);
write(a[i,j]:4);
end;
writeln;
end;
max:=a[1,1]; imax:=1; jmax:=1;
min:=a[1,1]; imin:=1; jmin:=1;
for i:=1 to m do
for j:=1 to n do
begin
if a[i,j]>max then begin max:=a[i,j]; imax:=i; jmax:=j; end;
if a[i,j]<min then begin min:=a[i,j]; imin:=i; jmin:=j; end;
end;
writeln('max = a[',imax,',',jmax,'] = ',max);
writeln('min = a[',imin,',',jmin,'] = ',min);
a[imax,jmax]:=min;
a[imin,jmin]:=max;
writeln('Полученный массив:');
for i:=1 to m do
begin
for j:=1 to n do write(a[i,j]:4);
writeln;
end;
end.
Пример:
Исходный массив:
69 2 25 92 32 43
98 77 49 29 48 5
30 8 95 83 37 83
31 6 47 91 82 65
86 31 62 70 82 38
max = a[2,1] = 98
min = a[1,2] = 2
Полученный массив:
69 98 25 92 32 43
2 77 49 29 48 5
30 8 95 83 37 83
31 6 47 91 82 65
86 31 62 70 82 38