program lol; var mas:array[1..20] of integer; max,min,i:integer; begin randomize; for i:=1 to 20 do begin mas[i]:=random(100); writeln('Element #',i,': ',mas[i]); end; writeln; for i:=1 to 20 do if mas[i] > max then max:=mas[i]; writeln('MAX: ',max); min:=max; for i:=1 to 20 do if mas[i] < min then min:=mas[i]; writeln('MIN: ',min); writeln; for i:=1 to 20 do if (mas[i] >= min) and (mas[i] <= max) and (mas[i] mod 5 = 0) and (mas[i] <> 0) then writeln('Element #',i,': ', mas[i]); readln; end.
PROFIT?
program lol;
var
mas:array[1..20] of integer;
max,min,i:integer;
begin
randomize;
for i:=1 to 20 do
begin
mas[i]:=random(100);
writeln('Element #',i,': ',mas[i]);
end;
writeln;
for i:=1 to 20 do if mas[i] > max then max:=mas[i];
writeln('MAX: ',max);
min:=max;
for i:=1 to 20 do if mas[i] < min then min:=mas[i];
writeln('MIN: ',min);
writeln;
for i:=1 to 20 do
if (mas[i] >= min) and (mas[i] <= max) and (mas[i] mod 5 = 0) and (mas[i] <> 0) then
writeln('Element #',i,': ', mas[i]);
readln;
end.
49
Объяснение:
n = 10
цикл для i от 1 до n - 1
n - 1 = 10 - 1 = 9
9 - 1 + 1 = 9
(количество повторов цикла = конечное значение i - начальное значение i + 1)
цикл выполнится 9 раз
если выполняется условие A[i] > A[i-1], то значение A[i] вычисляется по формуле A[i] = A[i] - A[i-1]
s = 0
i = 1
A[1] > A[0] 5 > 7 (НЕТ)
s = 0 + A[1] = 0 + 5 = 5
i = 2
A[2] > A[1] 13 > 5 (ДА)
A[2] = A[2] - A[1] = 13 - 5 = 8
s = 5 + A[2] = 5 + 8 = 13
i = 3
A[3] > A[2] 7 > 8 (НЕТ)
s = 13 + A[3] = 13 + 7 = 20
i = 4
A[4] > A[3] 5 > 7 (НЕТ)
s = 20 + A[4] = 20 + 5 = 25
i = 5
A[5] > A[4] 4 > 5 (НЕТ)
s = 25 + A[5] = 25 + 4 = 29
i = 6
A[6] > A[5] 11 > 4 (ДА)
A[6] = A[6] - A[5] = 11 - 4 = 7
s = 29 + A[6] = 29 + 7 = 36
i = 7
A[7] > A[6] 8 > 7 (ДА)
A[7] = A[7] - A[6] = 8 - 7 = 1
s = 36 + A[7] = 36 + 1 = 37
i = 8
A[8] > A[7] 10 > 1 (ДА)
A[8] = A[8] - A[7] = 10 - 1 = 9
s = 37 + A[8] = 37 + 9 = 46
i = 9
A[9] > A[8] 3 > 9 (НЕТ)
s = 46 + A[9] = 46 + 3 = 49