Дан одномерный массив из 15 элементов. Поставить в обратном порядке элементы, расположенные между максимальными и минимальными элементами, включая их — Pascal(Паскаль)

uses crt;
var
a:array[1..100]of integer;
i,n,max,min,pmax,pmin:integer;
begin clrscr;
write('n=');
read(n);
for i:=1 to n do
 begin
  write('a[',i,']=');
  read(a[i]);
 end;
writeln;
writeln('ishodnyi massiv:');
for i:=1 to n do
write(a[i],'  ');
max:=a[1];
min:=a[1];
writeln;
for i:=1 to n do
 begin
  if a[i]>max then
   begin
    max:=a[i];
    pmax:=i;
   end;
  if a[i]<min then
   begin
    min:=a[i];
    pmin:=i;
   end;
 end;
writeln('max=',max);
writeln('min=',min);
writeln;
writeln('preobrazovannyi massiv:');
if pmin<pmax then
 begin
  for i:=1 to pmin-1 do
  write(a[i],'  ');
  textcolor(red);
  for i:=pmax downto pmin do
  write(a[i],'  ');
  textcolor(white);
  for i:=pmax+1 to n do
  write(a[i],'  ');
 end;
if pmax<pmin then
 begin
  for i:=1 to pmax-1 do
  write(a[i],'  ');
  textcolor(red);
  for i:=pmin downto pmax do
  write(a[i],'  ');
  textcolor(white);
  for i:=pmin+1 to n do
  write(a[i],'  ');
 end;
readkey;
end.

Leave a Comment

61 − = 57