Python 3:
from random import randint
C = [randint(-100, 100) for _ in range(20)]
print(*C)
print(sum(filter(lambda el: el < 0, C)))
Аналог в PascalABC.NET:
begin
var C := ArrRandomInteger(20, -100, 100);
C.Println;
C.Where(x -> x < 0).Sum.Print;
end.
Паскаль, в "старом" стиле:
var
C: array[1..20] of integer;
i, s: integer;
randomize();
s := 0;
for i := 1 to 20 do
C[i] := random(201) - 100;
write(C[i], ' ');
if C[i] < 0 then
s := s + C[i];
end;
writeln();
write(s)
Python 3:
from random import randint
C = [randint(-100, 100) for _ in range(20)]
print(*C)
print(sum(filter(lambda el: el < 0, C)))
Аналог в PascalABC.NET:
begin
var C := ArrRandomInteger(20, -100, 100);
C.Println;
C.Where(x -> x < 0).Sum.Print;
end.
Паскаль, в "старом" стиле:
var
C: array[1..20] of integer;
i, s: integer;
begin
randomize();
s := 0;
for i := 1 to 20 do
begin
C[i] := random(201) - 100;
write(C[i], ' ');
if C[i] < 0 then
s := s + C[i];
end;
writeln();
write(s)
end.