Nhập vào 1 mảng 2 chiều nxn \[(n \leq 10)\]
In ra mảng 2 chiều nxn thỏa mãn:
1)Phần tử trong hàng tăng dần, tron cột tăng dần
2)hàng tăng, cột giảm
3)cột giảm, hàng tăng
https://www.mediafire.com/?a2md8wxi81201i2
var t:array[1..10,1..10] of integer;
g:array[1..100] of integer;
e:word;
i,j,f,n:word;
begin
write('Nhap n(n<=10): ');
readln
;
for i:=1 to n do for j:=1 to n do begin
write('Nhap phan tu (',i,',',j,') :');
readln(t[i,j]);
end;
{mang ban dau}
writeln('mang ban dau: ');
for i:=1 to n do begin
for j:=1 to n do write(t[i,j]:4,);
writeln;
end;
{1}
for i:=1 to n do for j:=1 to n do g[n*(j-1)+i]:=t[i,j];
for j:=n*n downto 2 do for i:=1 to j-1 do if g
>g[i+1] then begin
e:=g;
g:=g[i+1];
g[i+1]:=e;
end;
for i:=1 to n do for j:=1 to n do t[i,j]:=g[n*(j-1)+i];
writeln('cau1: ');
for i:=1 to n do begin
for j:=1 to n do write(t[i,j]:4);
writeln;
end;
{cau 2}
for f:=n downto 2 do for i:=1 to f-1 do for j:=1 to n do begin
e:=t[i,j];
t[i,j]:=t[i+1,j];
t[i+1,j]:=e;
end;
writeln('cau 2:');
for i:=1 to n do begin
for j:=1 to n do write(t[i,j]:4);
writeln;
end;
{cau3 cot tang, hang giam}
for f:=n downto 2 do for i:=1 to f-1 do for j:=1 to n do begin
e:=t[i,j];
t[i,j]:=t[i+1,j];
t[i+1,j]:=e;
end;
for f:=n downto 2 do for j:=1 to f-1 do for i:=1 to n do begin
e:=t[i,j];
t[i,j]:=t[i,j+1];
t[i,j+1]:=e;
end;
writeln('cau3:');
for i:=1 to n do begin
for j:=1 to n do write(t[i,j]:4);
writeln;
end;
readln
end.