Const n=10; var a:array[1..n] of integer; i:integer; begin Randomize; for i:=1 to n do begin a[i]:=random(21)-10; write(a[i]:4); end; writeln; for i:=1 to n do if a[i]<>0 then a[i]:=a[i]-a[n]; for i:=1 to n do write(a[i]:4); writeln; end.
// PascalABC.NET 3.1, сборка 1256 от 21.06.2016 begin var a:=ArrRandom(10,-20,20); a.Println; var c:=a[a.High]; a.Transform(x->x=0?x:x-c); a.Println end.
var
a:array[1..n] of integer;
i:integer;
begin
Randomize;
for i:=1 to n do
begin
a[i]:=random(21)-10;
write(a[i]:4);
end;
writeln;
for i:=1 to n do
if a[i]<>0 then a[i]:=a[i]-a[n];
for i:=1 to n do write(a[i]:4);
writeln;
end.
Пример:
3 4 2 -1 -5 6 -9 -2 0 2
1 2 0 -3 -7 4 -11 -4 0 0
begin
var a:=ArrRandom(10,-20,20); a.Println;
var c:=a[a.High];
a.Transform(x->x=0?x:x-c); a.Println
end.
Тестовое решение
-4 9 4 0 18 1 -8 -6 -8 12
-16 -3 -8 0 6 -11 -20 -18 -20 0