Const n=20; var a:array[1..n] of integer; s,p,i:integer; begin Randomize; for i:=1 to n do begin a[i]:=random(51); write(a[i],' '); end; writeln; s:=0; p:=1; for i:=1 to n do if a[i] mod 10 = 5 then begin s:=s+a[i]; p:=p*a[i]; end; writeln('s = ',s,' p = ',p); end.
Пример (для n=10): 18 43 5 30 46 39 21 26 19 25 s = 30 p = 125
var a:array[1..n] of integer;
s,p,i:integer;
begin
Randomize;
for i:=1 to n do begin
a[i]:=random(51);
write(a[i],' ');
end;
writeln;
s:=0; p:=1;
for i:=1 to n do
if a[i] mod 10 = 5 then begin s:=s+a[i]; p:=p*a[i]; end;
writeln('s = ',s,' p = ',p);
end.
Пример (для n=10):
18 43 5 30 46 39 21 26 19 25
s = 30 p = 125