в массиве А(N) поменяйте местами первый отрицательный и минимальный элементы
uses crt;
const N=10;var a:array[1..N] of integer; i,k,m,min,imin:integer;Beginreadln(m);for i:=1 to m do beginreadln(a[i]);min:=min+a[i];end;
for i:=1 to m do beginif a[i]<0 then begink:=i;break;end;end;
for i:=1 to m do beginif a[i]<min then beginmin:=a[i];imin:=i;end;end;
min:=a[imin];a[imin]:=a[k];a[k]:=min;
for i:=1 to m do write(a[i],' ');
end.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
uses crt;
const N=10;
var a:array[1..N] of integer;
i,k,m,min,imin:integer;
Begin
readln(m);
for i:=1 to m do begin
readln(a[i]);
min:=min+a[i];
end;
for i:=1 to m do begin
if a[i]<0 then begin
k:=i;
break;
end;
end;
for i:=1 to m do begin
if a[i]<min then begin
min:=a[i];
imin:=i;
end;
end;
min:=a[imin];
a[imin]:=a[k];
a[k]:=min;
for i:=1 to m do write(a[i],' ');
end.