Const n=10; var a:array[1..n] of integer; i,s,k:integer; begin Randomize; for i:=1 to n do begin a[i]:=random(51)-25; write(a[i]:4); end; writeln; s:=0; k:=0; for i:=1 to n do if a[i]<0 then begin s:=s+a[i]; k:=k+1; end; writeln('s = ',s,' k = ',k); end.
Пример: 21 5 -11 -6 -14 -9 1 -25 9 5 s = -65 k = 5
var
a:array[1..n] of integer;
i,s,k:integer;
begin
Randomize;
for i:=1 to n do
begin
a[i]:=random(51)-25;
write(a[i]:4);
end;
writeln;
s:=0; k:=0;
for i:=1 to n do
if a[i]<0
then begin s:=s+a[i]; k:=k+1; end;
writeln('s = ',s,' k = ',k);
end.
Пример:
21 5 -11 -6 -14 -9 1 -25 9 5
s = -65 k = 5