Цитата:
Сообщение от elkka
Выручайте меня, пожалуйста.
В прямоугольной матрице В с размером m x n заменить заданным вектором столбцы, содержащие хотя бы один нулевой элемент;
в полученной матрице вычислить суммы элементов строк, номера которых задаются целочисленным вектором.
Причём абсолютно всё нужно вводить с клавиатуры.
Заранее благодарю!
|
Получите:
Код:
Uses CRT;
Const
M=8; {Nuber of lines}
N=10; {Number of columns}
Var
B:Array[1..M,1..N] of Integer;
V,Sums:Array[1..M] of Integer;
Numbers:Set of Byte;
Nc,i,j,nl:Byte;
bo:boolean;
Begin
ClrScr;
Writeln('Initial matrix:');
For i:=1 to M do
begin
For j:=1 to N do
begin
Write('B[',i:2,',',j:2,']= ');
Readln(B[i,j]);
end;
Writeln;
end;
Writeln('Vector for replacement:');
For i:=1 to M do
begin
Write('V[',i:2,']= ');
Readln(V[i]);
end;
Nc:=0;
Numbers:=[];
Writeln('Numbers of lines for sums calculation ("0" to stop):');
Repeat
Write('Next number = ');
Readln(nl);
Inc(Nc);
Numbers:=Numbers+[nl];
Until (nl=0) or (Nc=M);
ClrScr;
Write('Initial:');
If 1 in Numbers then Write(' * ') else Write(' ');
For j:=1 to N do Write(B[1,j]:4);
Writeln(' Vector: ',V[1]:6);
For i:=2 to M do
begin
Write(' ');
If i in Numbers then Write(' * ') else Write(' ');
For j:=1 to N do Write(B[i,j]:4);
Writeln(' ',V[i]:6);
end;
Writeln;
For j:=1 to N do
begin
bo:=false;
i:=0;
Repeat
Inc(i);
If B[i,j]=0 then bo:=true;
Until bo or (i=M);
If bo then
For i:=1 to M do B[i,j]:=V[i];
end;
For i:=1 to M do
If i in Numbers then
begin
Sums[i]:=0;
For j:=1 to N do Inc(Sums[i],B[i,j]);
end;
Write('Changed: ');
For j:=1 to N do Write(B[1,j]:4);
If 1 in Numbers then
Writeln(' Sums: ',Sums[1]:6);
For i:=2 to M do
begin
Write(' ');
For j:=1 to N do Write(B[i,j]:4);
If i in Numbers then Writeln(' ',Sums[i]:6) else Writeln;
end;
ReadKey;
End.