//Pascal ABC.NET v3.1 сборка 1219
Const
n=10;
Var
ar:array[1..n] of integer;
k1,i,c,k2,k3:integer;
begin
randomize;
writeln('First array:');
for i:=1 to n do
begin
ar[i]:=random(9)-3;
write(ar[i]:4);
end;
writeln;
write('Enter index 1:');
readln(k1);
write('Enter index 2:');
readln(k2);
if (ar[k1]>0) and (ar[k2]>0) then
begin
c:=ar[k1];
ar[k1]:=ar[k2];
ar[k2]:=c;
end
else
begin
write('Enter index 3:');
readln(k3);
c:=ar[1];
ar[1]:=ar[k3];
ar[k3]:=c;
end;
writeln('Final array:');
for i:=1 to n do
write(ar[i]:4);
end.
Пример работы программы:
First array:
-1 -1 1 -1 0 -1 -2 -2 5 -2
Enter index 1:9
Enter index 2:1
Enter index 3:7
Final array:
-2 -1 1 -1 0 -1 -1 -2 5 -2