Сpascal 1) найти сумму всех элементов массива, заполненных случайными числами? 2) найти сумму четных элементов массива? 3) найти сумму элементов массива, стоящих на четных местах?
Program primer; const n =10; var a:array[1..n] of integer; s,i:integer; begin randomize; for i :=1 to n do begin a[i]:=random(19); readln(' ' ,a[i]); end; s:=0; for i :=1 to n do s:=s+a[i]; writeln('s=',s); readln; end.
program primer2; const n =10; var a:array[1..n] of integer; s,i:integer; begin randomize; for i :=1 to n do begin a[i]:=random(19); readln(' ' ,a[i]); end; s:=0; for i :=1 to n do if a[i] mod 2=0 then s:=s+a[i]; writeln('s=',s); readln; end.
program primer2; const n =10; var a:array[1..n] of integer; s,i:integer; begin randomize; for i :=1 to n do begin a[i]:=random(19); readln(' ' ,a[i]); end; s:=0; for i :=1 to n do if i mod 2 =0 then s:=s+a[i]; writeln('s=',s); readln; end.
const n =10;
var a:array[1..n] of integer;
s,i:integer;
begin
randomize;
for i :=1 to n do
begin
a[i]:=random(19);
readln(' ' ,a[i]);
end;
s:=0;
for i :=1 to n do
s:=s+a[i];
writeln('s=',s);
readln;
end.
program primer2;
const n =10;
var a:array[1..n] of integer;
s,i:integer;
begin
randomize;
for i :=1 to n do
begin
a[i]:=random(19);
readln(' ' ,a[i]);
end;
s:=0;
for i :=1 to n do
if a[i] mod 2=0 then s:=s+a[i];
writeln('s=',s);
readln;
end.
program primer2;
const n =10;
var a:array[1..n] of integer;
s,i:integer;
begin
randomize;
for i :=1 to n do
begin
a[i]:=random(19);
readln(' ' ,a[i]);
end;
s:=0;
for i :=1 to n do
if i mod 2 =0 then s:=s+a[i];
writeln('s=',s);
readln;
end.