Bài 1:
uses crt;
var a:array[1..100]of integer;
n,i,tam:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
begin
tam:=a[1];
a[1]:=a[n];
a[n]:=tam;
end;
writeln('Day so sau khi doi cho la: ');
for i:=1 to n do write(a[i]:4);
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
n,i,tam,max,min,vtmax,vtmin:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
for i:=1 to n do
if max=a[i] then vtmax:=i;
for i:=1 to n do
if min=a[i] then vtmin:=i;
begin
tam:=a[vtmax];
a[vtmax]:=a[vtmin];
a[vtmin]:=tam;
end;
for i:=1 to n do
write(a[i]:4);
readln;
end.