Var ar:array[1..n] of integer; i,j,c:integer; begin randomize; readln(c); writeln('Array:'); for i:=1 to n do begin ar[i]:=random(-10,10); write(ar[i]:4); end; for i:=1 to n-1 do for j:=i+1 to n do if (ar[i]>ar[j]) and (ar[i]<0) and (ar[j]<0) and (ar[i] mod c=0) and (ar[j] mod c=0) then swap(ar[i],ar[j]); writeln; writeln('Final array:'); for i:=1 to n do write(ar[i]:4); end.
Пример ввода: 2 Пример вывода: Array: -7 3 9 -2 7 -7 3 -6 -6 -3 Final array: -7 3 9 -6 7 -7 3 -6 -2 -3
Const
n=10;
Var
ar:array[1..n] of integer;
i,j,c:integer;
begin
randomize;
readln(c);
writeln('Array:');
for i:=1 to n do
begin
ar[i]:=random(-10,10);
write(ar[i]:4);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if (ar[i]>ar[j]) and (ar[i]<0) and (ar[j]<0) and (ar[i] mod c=0) and (ar[j] mod c=0) then swap(ar[i],ar[j]);
writeln;
writeln('Final array:');
for i:=1 to n do
write(ar[i]:4);
end.
Пример ввода:
2
Пример вывода:
Array:
-7 3 9 -2 7 -7 3 -6 -6 -3
Final array:
-7 3 9 -6 7 -7 3 -6 -2 -3