Const n=10; var a:array[1..n] of integer; i,s,p:integer; begin writeln('Исходный массив:'); for i:=1 to n do begin a[i]:=random(21)-10; write(a[i]:4); end; writeln; s:=0; p:=1; for i:=1 to n do begin if i mod 2 = 0 then s:=s+a[i]; if a[i] mod 3 = 0 then p:=p*a[i]; end; writeln('s = ',s,' p = ',p); end.
Пример: Исходный массив: -4 -9 2 -2 4 6 -8 -5 7 -5 s = -15 p = -54
Answers & Comments
Verified answer
Const n=10;var a:array[1..n] of integer;
i,s,p:integer;
begin
writeln('Исходный массив:');
for i:=1 to n do
begin
a[i]:=random(21)-10;
write(a[i]:4);
end;
writeln;
s:=0;
p:=1;
for i:=1 to n do
begin
if i mod 2 = 0 then s:=s+a[i];
if a[i] mod 3 = 0 then p:=p*a[i];
end;
writeln('s = ',s,' p = ',p);
end.
Пример:
Исходный массив:
-4 -9 2 -2 4 6 -8 -5 7 -5
s = -15 p = -54