Дан массив из 20 элементов случайных чисел из диапазона [ -1; 1] . каких элементов больше, положительных , отрицательных или равных нулю.паскаль

antongrom68 antongrom68    3   26.08.2019 12:50    0

Ответы
zlatapitch1234 zlatapitch1234  20.08.2020 15:55
Program n1;
const n=20;
var a: array[1..n] of integer;
i,kn,ko,kp: integer;
function max(a,b,c: integer): string;
begin
max:=' ';
if (a>b) and (a>c) then max:='0 больше'
else if (b>c) and (b>a) then max:='отрицательных больше'
else if (c>a) and (c>b) then max:='положительных больше'
else if (a=c) and (c=b) then max:='количество всех элементов одинаковое'
else if a=b then max:='0 и отрицательных поровну'
else if b=c then max:='положительных и отрицательных поровну'
else if a=c then max:='0 и положительных поровну'
else max:='ошибка';
end;
begin
randomize;
write('исходный массив: ');
kn:=0;
kp:=0;
ko:=0;
for i:=1 to n do
begin
a[i]:=random(3)-1;
write(a[i],' ');
if a[i]>0 then kp:=kp+1
else if a[i]<0 then ko:=ko+1
else kn:=kn+1;
end;
writeln;
write(max(kn,ko,kp));
end.
ПОКАЗАТЬ ОТВЕТЫ
Другие вопросы по теме Информатика