(acho que são essas as regras para se multiplicar duas matrizes):
Program multiplicacao_de_matrizes;
Var matrizA: array [1..50,1..50] of integer;
matrizB: array [1..50,1..50] of integer;
matrizAB: array [1..50,1..50] of integer;
lin1, col1, lin2, col2, i, j, k: integer;
Begin
writeln;
writeln('-------- Multiplicação de 2 matrizes --------');
writeln;
writeln('Para ser possivel a multiplicação de duas matrizes');
writeln(' o numero de colunas da primeira matriz');
writeln(' deve ser igual ao numero de linhas da segunda');
writeln;
write('Digite o numero de linhas da primeira matriz: ');
readln(lin1);
write('Digite o numero de colunas da primeira matriz: ');
readln(col1);
writeln;
write('Digite o numero de linhas da segunda matriz: ');
readln(lin2);
write('Digite o numero de colunas da segunda matriz: ');
readln(col2);
writeln;
if ((col1)=(lin2)) then
begin
writeln('Escreva os elementos da matriz A: ');
for i:=1 to lin1 do
begin
for j:=1 to col1 do
begin
write('a',i,j,': ');
readln(matrizA[i,j]);
end;
end;
writeln;
writeln('Escreva os elementos da matriz B: ');
for i:=1 to lin2 do
begin
for j:=1 to col2 do
begin
write('b',i,j,': ');
readln(matrizB[i,j]);
end;
end;
for i:=1 to lin1 do
begin
for j:=1 to col2 do
begin
matrizAB[i,j]:=0;
for k:=1 to lin1 do
matrizAB[i,j]:=matrizAB[i,j]+matrizA[i,k]*matrizB[k,j];
end;
end;
writeln;
writeln('A matriz A*B :');
for i:=1 to lin1 do
begin
for j:=1 to col2 do
write('ab',i,j,': ', matrizAB[i,j],' ');
writeln;
end;
end else writeln('Nao eh possivel multiplicar essas matrizes');
End.
by Ernesto



Postagens
Não informado
