var
A: array [1..5] of Integer;
i, s: Integer;
begin
WriteLn ('Массив:');
s := 0;
Randomize;
for i := 1 to 5 do begin
A [i] := Random (10);
WriteLn (i, ': ', A [i]);
if A [i] in [8, 2, 4] then
s := s + A [i];
end;
WriteLn ('Сумма элементов 8, 2, 4 = ', s);
end.
# Код на Python
import random
array = [random.randint(0, 9) for i in range(5)]
print(array, sum([i for i in array if i in [2, 4, 8]]), sep="\n")
var
A: array [1..5] of Integer;
i, s: Integer;
begin
WriteLn ('Массив:');
s := 0;
Randomize;
for i := 1 to 5 do begin
A [i] := Random (10);
WriteLn (i, ': ', A [i]);
if A [i] in [8, 2, 4] then
s := s + A [i];
end;
WriteLn ('Сумма элементов 8, 2, 4 = ', s);
end.
# Код на Python
import random
array = [random.randint(0, 9) for i in range(5)]
print(array, sum([i for i in array if i in [2, 4, 8]]), sep="\n")