PascalABC.NET 3.3.5, сборка 1662 от 29.04.2018 Внимание! Если программа не работает, обновите версию!
begin var A:=MatrGen(6,7,(i,j)->Sin(i+1)+Cos(3*(j+1))); A.Println(10,6); Writeln(70*'-'); var B:=A.ElementsWithIndexes.Where(t->t[1].IsEven and t[2].IsEven) .Select(t->t[0]).ToArray; B.Println; var m:=B.Where(t->t>0).DefaultIfEmpty.Average; Writeln('Искомое среднее равно ',m); var f:=OpenWrite('MyFile.txt'); for var i:=0 to A.RowCount-1 do begin for var j:=0 to A.ColCount-1 do Write(f,A[i,j],' '); Writeln(f); end; Writeln(f); for var i:=0 to B.Length-1 do Write(f,B[i],' '); f.Close; end.
var a:array[1..10,1..10]of integer; b:array[1..10,1..10]of integer; i,j,s1,s2:integer; begin for i:=1 to 10 do for j:=1 to 10 do begin a[i,j]:=random(9)+1; b[i,j]:=random(9)+1; end; for i:=1 to 10 do begin for j:=1 to 10 do write(a[i,j],' '); if j=10 then writeln; end; writeln; for i:=1 to 10 do begin for j:=1 to 10 do write(b[i,j],' '); if j=10 then writeln; end; for i:=1 to 10 do for j:=1 to 10 do if i=j then begin s1:=s1+a[i,j]; s2:=s2+b[i,j]; end; writeln; if s1>s2 then for i:=1 to 10 do begin for j:=1 to 10 do write(a[i,j],' '); if j=10 then writeln; end else for i:=1 to 10 do begin for j:=1 to 10 do write(b[i,j],' '); if j=10 then writeln; end; end.
Внимание! Если программа не работает, обновите версию!
begin
var A:=MatrGen(6,7,(i,j)->Sin(i+1)+Cos(3*(j+1)));
A.Println(10,6); Writeln(70*'-');
var B:=A.ElementsWithIndexes.Where(t->t[1].IsEven and t[2].IsEven)
.Select(t->t[0]).ToArray;
B.Println;
var m:=B.Where(t->t>0).DefaultIfEmpty.Average;
Writeln('Искомое среднее равно ',m);
var f:=OpenWrite('MyFile.txt');
for var i:=0 to A.RowCount-1 do begin
for var j:=0 to A.ColCount-1 do
Write(f,A[i,j],' ');
Writeln(f);
end;
Writeln(f);
for var i:=0 to B.Length-1 do Write(f,B[i],' ');
f.Close;
end.
var a:array[1..10,1..10]of integer;
b:array[1..10,1..10]of integer;
i,j,s1,s2:integer;
begin
for i:=1 to 10 do for j:=1 to 10 do begin a[i,j]:=random(9)+1; b[i,j]:=random(9)+1; end;
for i:=1 to 10 do begin for j:=1 to 10 do write(a[i,j],' '); if j=10 then writeln; end;
writeln;
for i:=1 to 10 do begin for j:=1 to 10 do write(b[i,j],' '); if j=10 then writeln; end;
for i:=1 to 10 do
for j:=1 to 10 do
if i=j then begin
s1:=s1+a[i,j];
s2:=s2+b[i,j];
end;
writeln;
if s1>s2 then for i:=1 to 10 do begin for j:=1 to 10 do write(a[i,j],' '); if j=10 then writeln; end else
for i:=1 to 10 do begin for j:=1 to 10 do write(b[i,j],' '); if j=10 then writeln; end;
end.