Const n=10; var a:array[1..n] of integer; i,k1,k2,s:integer; begin Randomize; writeln('Массив A:'); for i:=1 to n do begin a[i]:=random(51)-25; write(a[i]:4); end; writeln; for i:=1 to n do begin if a[i]>0 then k2:=i; if a[n+1-i]>0 then k1:=n+1-i; end; writeln('k1 = ',k1,' k2 = ',k2); s:=0; for i:=k1+1 to k2-1 do s:=s+a[i]; writeln('s = ',s,' k = ',k2-k1-1); end.
var a:array[1..n] of integer;
i,k1,k2,s:integer;
begin
Randomize;
writeln('Массив A:');
for i:=1 to n do
begin
a[i]:=random(51)-25;
write(a[i]:4);
end;
writeln;
for i:=1 to n do
begin
if a[i]>0 then k2:=i;
if a[n+1-i]>0 then k1:=n+1-i;
end;
writeln('k1 = ',k1,' k2 = ',k2);
s:=0;
for i:=k1+1 to k2-1 do s:=s+a[i];
writeln('s = ',s,' k = ',k2-k1-1);
end.
Пример:
Массив A:
-9 -4 -22 -1 19 -23 -24 16 -12 -25
k1 = 5 k2 = 8
s = -47 k = 2