矩阵乘法C=A×B1 2 5 10 1 2 0 A=3 4 6 B= 8 3 4 77 5 6 9要把C输出来.用for语句循环嵌套,用pascal
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/27 01:20:58
![矩阵乘法C=A×B1 2 5 10 1 2 0 A=3 4 6 B= 8 3 4 77 5 6 9要把C输出来.用for语句循环嵌套,用pascal](/uploads/image/z/3893676-60-6.jpg?t=%E7%9F%A9%E9%98%B5%E4%B9%98%E6%B3%95C%EF%BC%9DA%C3%97B1+2+5+10+1+2+0+A%3D3+4+6+B%3D+8+3+4+77+5+6+9%E8%A6%81%E6%8A%8AC%E8%BE%93%E5%87%BA%E6%9D%A5.%E7%94%A8for%E8%AF%AD%E5%8F%A5%E5%BE%AA%E7%8E%AF%E5%B5%8C%E5%A5%97%2C%E7%94%A8pascal)
矩阵乘法C=A×B1 2 5 10 1 2 0 A=3 4 6 B= 8 3 4 77 5 6 9要把C输出来.用for语句循环嵌套,用pascal
矩阵乘法C=A×B
1 2 5 10 1 2 0
A=3 4 6 B= 8 3 4 7
7 5 6 9
要把C输出来.
用for语句循环嵌套,
用pascal
矩阵乘法C=A×B1 2 5 10 1 2 0 A=3 4 6 B= 8 3 4 77 5 6 9要把C输出来.用for语句循环嵌套,用pascal
program matrix;
const
maxn=100;
var
a,b,c:array[1..maxn,1..maxn]of integer;
i,j,k,n1,m1,n2,m2:integer;
begin
readln(n1,m1); {A矩阵的行数n1和列数m1}
for i:=1 to n1 do
begin
for j:=1 to m1 do read(a[i,j]);
readln;
end;
readln(n2,m2); {B矩阵的行数n2和列数m2(由于要进行矩阵乘法,故必须m1=n2)}
for i:=1 to n2 do
begin
for j:=1 to m2 do read(b[i,j]);
readln;
end;
for i:=1 to n1 do
for j:=1 to m2 do
for k:=1 to n2 do
c[i,j]:=c[i,j]+a[i,k]*b[k,j];
{矩阵乘法的计算公式:a[i,j]:=∑(k=0→m1/n2) a[i,k]*a[k,j]}
for i:=1 to n1 do
begin
for j:=1 to m2 do write(c[i,j],' ');
writeln;
end;
end.
{例:
输入:
2 3 >n2,m2
10 1 2 0
8 3 4 7
7 5 6 9
输出:
61 32 40 59
104 45 58 82
注:n*m的矩阵与m*t的矩阵相乘,得到一个n*t的矩阵}