uses crt; const n = 20; var a:array [1..n] of integer; sdvig,i,k:integer; begin randomize; for i:=1 to n do begin a[i]:=random(100)-50; write(a[i]:3,' '); end; writeln(); sdvig:=0; for i:=1 to n do if a[i]=0 then sdvig:=sdvig+1 else begin a[i-sdvig]:=a[i]; end; k:=n-sdvig; for i:=1 to k do write(a[i]:3,' '); end.
uses crt; var m,i,k:integer; a:array [1..100] of integer; begin clrscr; randomize; write('Количество элементов массива: ');readln(k); for i:=1 to k do begin a[i]:=random(100)-50; write(a[i],' '); end; m:=0; writeln; for i:=1 to k do if a[i]=0 then inc(m) else a[i-m]:=a[i];k:=k-m; for i:=1 to k do write(a[i],' ');readln; end.
Answers & Comments
Program Sherilusha;
uses crt;
const n = 20;
var
a:array [1..n] of integer;
sdvig,i,k:integer;
begin
randomize;
for i:=1 to n do
begin
a[i]:=random(100)-50;
write(a[i]:3,' ');
end;
writeln();
sdvig:=0;
for i:=1 to n do
if a[i]=0 then
sdvig:=sdvig+1
else
begin
a[i-sdvig]:=a[i];
end;
k:=n-sdvig;
for i:=1 to k do
write(a[i]:3,' ');
end.
Verified answer
uses crt;
var
m,i,k:integer; a:array [1..100] of integer;
begin
clrscr; randomize;
write('Количество элементов массива: ');readln(k);
for i:=1 to k do
begin
a[i]:=random(100)-50;
write(a[i],' ');
end;
m:=0;
writeln;
for i:=1 to k do
if a[i]=0 then inc(m)
else a[i-m]:=a[i];k:=k-m;
for i:=1 to k do
write(a[i],' ');readln;
end.