
Gragar
6 год назад
Дан массив подсчитать сумму отрицательных элементов?
ОТВЕТЫ

Адрианович
Jul 10, 2019
Const
handsfree = true;
var
a: array[1..100] of real;
i, n: integer;
sum: real;
begin
{ввод массива}
if handsfree then
n := random(20) + 5
else begin
write(n = );
readln(n);
end;
writeln(Данные массива:);
for i := 1 to n do
begin
if handsfree then begin
a[i] := random(100) - 50;
write(a[i], );
end
else readln(a[i]);
end;
writeln();
{подсчет суммы и произведения и агригатов}
sum := 0;
for i := 1 to n do
if a[i] lt; 0 then {если нужен фильтр}
sum := sum + a[i];
writeln(sum = , sum);
end.
handsfree = true;
var
a: array[1..100] of real;
i, n: integer;
sum: real;
begin
{ввод массива}
if handsfree then
n := random(20) + 5
else begin
write(n = );
readln(n);
end;
writeln(Данные массива:);
for i := 1 to n do
begin
if handsfree then begin
a[i] := random(100) - 50;
write(a[i], );
end
else readln(a[i]);
end;
writeln();
{подсчет суммы и произведения и агригатов}
sum := 0;
for i := 1 to n do
if a[i] lt; 0 then {если нужен фильтр}
sum := sum + a[i];
writeln(sum = , sum);
end.
268