Const n=20; var a:array[1..n] of integer; i,k,m:integer; begin Randomize; writeln('Массив A:'); for i:=1 to n do begin a[i]:=random(51); write(a[i]:3); end; writeln; k:=0; m:=0; for i:=1 to n-1 do begin if a[i+1]>a[i] then begin m:=m+1; end else begin if m>0 then k:=k+1; m:=0; end; end; if m>0 then k:=k+1; writeln('k = ',k); end.
Answers & Comments
Verified answer
Const n=20;var a:array[1..n] of integer;
i,k,m:integer;
begin
Randomize;
writeln('Массив A:');
for i:=1 to n do
begin
a[i]:=random(51);
write(a[i]:3);
end;
writeln;
k:=0; m:=0;
for i:=1 to n-1 do
begin
if a[i+1]>a[i] then begin m:=m+1; end
else begin if m>0 then k:=k+1; m:=0; end;
end;
if m>0 then k:=k+1;
writeln('k = ',k);
end.
Пример:
Массив A:
7 30 22 0 17 4 2 32 39 26 23 41 1 38 47 21 38 31 43 7
k = 7