// PascalABC.NET 3.1, сборка 1256 от 21.06.2016 var i,j,k,n:integer; a,b,c:array[,] of integer; begin Write('Число строк (столбцов) матрицы: '); Read(n); SetLength(a,n,n); SetLength(b,n,n); SetLength(c,n,n); Randomize; Writeln('Матрица A'); for i:=0 to n-1 do begin for j:=0 to n-1 do begin a[i,j]:=Random(90)+10; Write(a[i,j]:3) end; Writeln end; Writeln('Матрица B'); for i:=0 to n-1 do begin for j:=0 to n-1 do begin b[i,j]:=Random(90)+10; Write(b[i,j]:3) end; Writeln end; // умножение и вывод Writeln('Матрица C'); for i:=0 to n-1 do begin for j:=0 to n-1 do begin c[i,j]:=0; for k:=0 to n-1 do c[i,j]:=c[i,j]+a[i,k]*b[k,j]; Write(c[i,j]:6) end; Writeln end; end.
Var ma1,ma2,mar:array[1..n,1..n] of integer; i,j,z:integer; begin randomize; writeln('Matrix 1:'); for i:=1 to n do begin for j:=1 to n do begin ma1[i,j]:=random(10); write(ma1[i,j]:4); end; writeln; end; writeln('Matrix 2:'); for i:=1 to n do begin for j:=1 to n do begin ma2[i,j]:=random(10); write(ma2[i,j]:4); end; writeln; end; writeln('Final matrix:'); for i:=1 to n do begin for j:=1 to n do begin for z:=1 to n do mar[i,j]:=mar[i,j]+ma2[z,j]*ma1[i,z]; write(mar[i,j]:4); end; writeln; end; end.
//C вводом размерности
Var ma1,ma2,mar:array[,] of integer; i,j,z,n:integer; begin randomize; readln(n); setlength(ma1,n,n); setlength(ma2,n,n); setlength(mar,n,n); writeln('Matrix 1:'); for i:=0 to n-1 do begin for j:=0 to n-1 do begin ma1[i,j]:=random(10); write(ma1[i,j]:4); end; writeln; end; writeln('Matrix 2:'); for i:=0 to n-1 do begin for j:=0 to n-1 do begin ma2[i,j]:=random(10); write(ma2[i,j]:4); end; writeln; end; writeln('Final matrix:'); for i:=0 to n-1 do begin for j:=0 to n-1 do begin for z:=0 to n-1 do mar[i,j]:=mar[i,j]+ma2[z,j]*ma1[i,z]; write(mar[i,j]:4); end; writeln; end; end.
var
i,j,k,n:integer;
a,b,c:array[,] of integer;
begin
Write('Число строк (столбцов) матрицы: '); Read(n);
SetLength(a,n,n);
SetLength(b,n,n);
SetLength(c,n,n);
Randomize;
Writeln('Матрица A');
for i:=0 to n-1 do begin
for j:=0 to n-1 do begin
a[i,j]:=Random(90)+10;
Write(a[i,j]:3)
end;
Writeln
end;
Writeln('Матрица B');
for i:=0 to n-1 do begin
for j:=0 to n-1 do begin
b[i,j]:=Random(90)+10;
Write(b[i,j]:3)
end;
Writeln
end;
// умножение и вывод
Writeln('Матрица C');
for i:=0 to n-1 do begin
for j:=0 to n-1 do begin
c[i,j]:=0;
for k:=0 to n-1 do c[i,j]:=c[i,j]+a[i,k]*b[k,j];
Write(c[i,j]:6)
end;
Writeln
end;
end.
Тестовое решение
Число строк (столбцов) матрицы: 5
Матрица A
25 81 17 87 40
36 79 25 98 66
90 64 73 30 54
75 12 92 48 84
94 91 71 96 94
Матрица B
38 96 54 10 24
66 47 13 15 81
87 33 35 11 19
48 20 16 40 14
34 94 91 97 64
Матрица C
13311 12268 8030 9012 11262
15705 16158 11420 12142 13334
17271 19733 13641 9101 12607
16806 19656 15838 12010 10568
23559 26400 18834 16044 18336
//Без ввода размерности
Const
n=3;
Var
ma1,ma2,mar:array[1..n,1..n] of integer;
i,j,z:integer;
begin
randomize;
writeln('Matrix 1:');
for i:=1 to n do
begin
for j:=1 to n do
begin
ma1[i,j]:=random(10);
write(ma1[i,j]:4);
end;
writeln;
end;
writeln('Matrix 2:');
for i:=1 to n do
begin
for j:=1 to n do
begin
ma2[i,j]:=random(10);
write(ma2[i,j]:4);
end;
writeln;
end;
writeln('Final matrix:');
for i:=1 to n do
begin
for j:=1 to n do
begin
for z:=1 to n do
mar[i,j]:=mar[i,j]+ma2[z,j]*ma1[i,z];
write(mar[i,j]:4);
end;
writeln;
end;
end.
//C вводом размерности
Var
ma1,ma2,mar:array[,] of integer;
i,j,z,n:integer;
begin
randomize;
readln(n);
setlength(ma1,n,n);
setlength(ma2,n,n);
setlength(mar,n,n);
writeln('Matrix 1:');
for i:=0 to n-1 do
begin
for j:=0 to n-1 do
begin
ma1[i,j]:=random(10);
write(ma1[i,j]:4);
end;
writeln;
end;
writeln('Matrix 2:');
for i:=0 to n-1 do
begin
for j:=0 to n-1 do
begin
ma2[i,j]:=random(10);
write(ma2[i,j]:4);
end;
writeln;
end;
writeln('Final matrix:');
for i:=0 to n-1 do
begin
for j:=0 to n-1 do
begin
for z:=0 to n-1 do
mar[i,j]:=mar[i,j]+ma2[z,j]*ma1[i,z];
write(mar[i,j]:4);
end;
writeln;
end;
end.