Const n=10; var a:array[1..n] of integer; i,s1,s2:integer; begin Randomize; writeln('Массив A:'); for i:=1 to n do begin a[i]:=random(51); write(a[i]:4); end; writeln; s1:=0; s2:=0; for i:=1 to n do if i mod 2 = 1 then s1:=s1+a[i] else s2:=s2+a[i]; writeln('s1 = ',s1,' s2 = ',s2); end.
var a:array[1..n] of integer;
i,s1,s2:integer;
begin
Randomize;
writeln('Массив A:');
for i:=1 to n do
begin
a[i]:=random(51);
write(a[i]:4);
end;
writeln;
s1:=0; s2:=0;
for i:=1 to n do
if i mod 2 = 1 then s1:=s1+a[i] else s2:=s2+a[i];
writeln('s1 = ',s1,' s2 = ',s2);
end.
Пример:
Массив A:
21 46 43 5 40 32 26 34 29 48
s1 = 159 s2 = 165
Подробнее - на -