Const n=21; var q:array[1..n] of integer; i,s,k:integer; begin Randomize; for i:=1 to n do begin q[i]:=random(51)-10; write(q[i]:4); end; writeln; k:=0; s:=0; for i:=1 to n do if q[i]<0 then begin s:=s+q[i]; k:=k+1; end; writeln('Среднее арифметическое отрицательных элементов = ',s/k); end.
Var dc:set of char; s1,s2:string; i:integer; begin dc:=['A'..'D','a'..'d']; s1:='То avoid the impression of the tail wagging the dog, '+ 'the president cannot be seen bending to the wishes of a minority.'; s2:=''; for i:=1 to length(s1) do if not(s1[i] in dc) then s2:=s2+s1[i]; Writeln('Исходная строка: ',s1); s1:=s2; Writeln('Результирующая строка: ',s1) end.
Тестовое решение: Исходная строка: То avoid the impression of the tail wagging the dog, the president cannot be seen bending to the wishes of a minority. Результирующая строка: То voi the impression of the til wgging the og, the presient nnot e seen ening to the wishes of minority.
var q:array[1..n] of integer;
i,s,k:integer;
begin
Randomize;
for i:=1 to n do
begin
q[i]:=random(51)-10;
write(q[i]:4);
end;
writeln;
k:=0; s:=0;
for i:=1 to n do
if q[i]<0 then begin s:=s+q[i]; k:=k+1; end;
writeln('Среднее арифметическое отрицательных элементов = ',s/k);
end.
Пример:
16 -1 -7 5 13 11 -2 -10 36 19 3 34 23 29 12 28 9 39 33 16 -6
Среднее арифметическое отрицательных элементов = -5.2