Найти сумму всех четн. элементов многомерного массива.(через датчик случайных чисел)
Answers & Comments
varanchik
const n=5; var a: array[1..n,1..n] of integer; j,i,s:integer; begin s:=0; randomize; for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(100); write(a[i,j]:4); if a[i,j] mod 2=0 then s:=s+a[i,j]; end; writeln; end; writeln('S=',s); readln end.
Answers & Comments
var
a: array[1..n,1..n] of integer;
j,i,s:integer;
begin
s:=0;
randomize;
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(100);
write(a[i,j]:4);
if a[i,j] mod 2=0 then
s:=s+a[i,j];
end;
writeln;
end;
writeln('S=',s);
readln
end.