Const n=8; var a:array[1..n,1..n] of integer; i,j,k,s,s1,si,dmin,smin:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(50); write(a[i,j]:4); end; writeln; end; write('k = '); readln(k); s:=0; for j:=1 to n do s:=s+a[k,j]; writeln('s = ',s); dmin:=999999; smin:=999999; for i:=1 to n do if i<>k then begin s1:=0; for j:=1 to n do s1:=s1+a[i,j]; writeln('s',i,' = ',s1); if abs(s1-s)<dmin then begin dmin:=abs(s1-s); smin:=s1; si:=i; end; end; writeln('Номер строки = ',si,', smin = ',smin); end.
// PascalABC.NET 3.1, сборка 1219 от 16.04.2016 type Matrix=array[,] of integer;
procedure MatPrint(a:Matrix); begin var m:=Length(a,1)-1; for var i:=0 to Length(a,0)-1 do begin for var j:=0 to m do Write(a[i,j]:4); Writeln end end;
function IsEqual(a:Matrix; col:integer):boolean; begin var s:=sign(a[0,col]); for var i:=1 to Length(a,0)-1 do s+=sign(a[i,col]); if (s=0) then Result:=(a[0,col]<>0) else Result:=false end;
procedure DeleteCol(var a:Matrix; col:integer); begin var n:=Length(a,0)-1; var m:=Length(a,1)-1; for var j:=col+1 to Length(a,1)-1 do for var i:=0 to n do a[i,j-1]:=a[i,j]; SetLength(a,n+1,m) end;
begin var n:=ReadInteger('Строк:'); var m:=ReadInteger('Столбцов:'); var a:=MatrixRandom(n,m,-99,99); Writeln('Исходная матрица'); MatPrint(a); for var j:=Length(a,1)-1 downto 0 do if IsEqual(a,j) then DeleteCol(a,j); Writeln('Результирующая матрица'); MatPrint(a); end.