Ответы
Ответ дал:
2
{в этом нет никакого смысла, матрица B не зависит от A и всегда единичная, так что матрица C = A в любом случае}
const
n = 4;
type
matrix = array[1..n,1..n] of integer;
function max(var a:matrix):integer;
var
m,i,j: integer;
begin
m := a[1,1];
for i := 1 to n do
for j := 1 to n do
if a[i,j] > m then
m := a[i,j];
max := m
end;
procedure mult(var a,b,c:matrix);
var
i,j,k: integer;
begin
for i := 1 to n do
for j := 1 to n do
begin
c[i,j] := 0;
for k := 1 to n do
c[i,j] := c[i,j] + a[i,k] * b[k,j]
end;
end;
var
a,b,c: matrix;
maxA,maxB: integer;
i,j: integer;
begin
for i := 1 to n do
for j := 1 to n do
read(a[i,j]);
maxA := max(a);
writeln('MaxA: ',maxA);
for i := 1 to n do
for j := 1 to n do
if i = j then b[i,j] := 1
else b[i,j] := 0;
writeln('B:');
for i := 1 to n do
begin
for j := 1 to n do
write(b[i,j],' ');
writeln
end;
maxB := max(b);
writeln('MaxB: ',maxB);
if maxA > maxB then
mult(a,b,c)
else
mult(b,a,c);
writeln('C:');
for i := 1 to n do
begin
for j := 1 to n do
write(c[i,j],' ');
writeln
end
end.
const
n = 4;
type
matrix = array[1..n,1..n] of integer;
function max(var a:matrix):integer;
var
m,i,j: integer;
begin
m := a[1,1];
for i := 1 to n do
for j := 1 to n do
if a[i,j] > m then
m := a[i,j];
max := m
end;
procedure mult(var a,b,c:matrix);
var
i,j,k: integer;
begin
for i := 1 to n do
for j := 1 to n do
begin
c[i,j] := 0;
for k := 1 to n do
c[i,j] := c[i,j] + a[i,k] * b[k,j]
end;
end;
var
a,b,c: matrix;
maxA,maxB: integer;
i,j: integer;
begin
for i := 1 to n do
for j := 1 to n do
read(a[i,j]);
maxA := max(a);
writeln('MaxA: ',maxA);
for i := 1 to n do
for j := 1 to n do
if i = j then b[i,j] := 1
else b[i,j] := 0;
writeln('B:');
for i := 1 to n do
begin
for j := 1 to n do
write(b[i,j],' ');
writeln
end;
maxB := max(b);
writeln('MaxB: ',maxB);
if maxA > maxB then
mult(a,b,c)
else
mult(b,a,c);
writeln('C:');
for i := 1 to n do
begin
for j := 1 to n do
write(c[i,j],' ');
writeln
end
end.
Вас заинтересует
5 месяцев назад
1 год назад
5 лет назад
5 лет назад
7 лет назад