Const n=10;
Var
a:array[1..2*n] of integer;
i,j,l,k,r:integer;
Begin
Randomize;
for i:=1 to n do begin
a[i]:=random(21);
write(a[i]:3);
end;
writeln;
Write('k = ');Readln(k);
Write('r = ');Readln(r);
For i:=n downto 1 do
if a[i] mod r = 0 then
begin
l:=l+1;
for j:=n+l-1 downto i do a[j+1]:=a[j];
a[i]:=k;
end;
for i:=1 to n+l do write(a[i]:3);
writeln;
End.
Пример:
2 12 3 20 1 9 11 8 15 14
k = 5
r = 2
5 2 5 12 3 5 20 1 9 11 5 8 15 5 14