with Ada.Text_IO ; use Ada.Text_IO ;
with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ;
procedure Q5L is
-- Definindo tipos para as matrizes
type Matrix is array ( 1 .. 10 , 1 .. 10 ) of Integer; -- Máximo de 10x10
A, B, C : Matrix; -- Matrizes A, B e C
M, N, P, Q : Integer; -- Dimensões das matrizes
begin
-- Entrada da matriz A
Put( "Digite o número de linhas da matriz A (m): " ) ;
Get( M) ;
Put( "Digite o número de colunas da matriz A (n): " ) ;
Get( N) ;
Put_Line( "Digite os elementos da matriz A:" ) ;
for I in 1 .. M loop
for J in 1 .. N loop
Put( "Elemento (" & Integer'Image( I) & ", " & Integer'Image( J) & "): " ) ;
Get( A( I, J) ) ;
end loop ;
end loop ;
-- Entrada da matriz B
Put( "Digite o número de linhas da matriz B (p): " ) ;
Get( P) ;
Put( "Digite o número de colunas da matriz B (q): " ) ;
Get( Q) ;
Put_Line( "Digite os elementos da matriz B:" ) ;
for I in 1 .. P loop
for J in 1 .. Q loop
Put( "Elemento (" & Integer'Image( I) & ", " & Integer'Image( J) & "): " ) ;
Get( B( I, J) ) ;
end loop ;
end loop ;
-- Inicializando a matriz C com zeros
for I in 1 .. M loop
for J in 1 .. Q loop
C( I, J) := 0 ;
end loop ;
end loop ;
-- Calculando a matriz C = A * B
for I in 1 .. M loop
for J in 1 .. Q loop
for K in 1 .. N loop
-- Considerando que elementos fora do tamanho da matriz são 0
C( I, J) := C( I, J) + A( I, K) * ( if K <= P then B( K, J) else 0 ) ;
end loop ;
end loop ;
end loop ;
-- Exibindo a matriz C
Put_Line( "A matriz C = A * B é:" ) ;
for I in 1 .. M loop
for J in 1 .. Q loop
Put( Integer'Image( C( I, J) ) & " " ) ;
end loop ;
New_Line; -- Nova linha após cada linha da matriz
end loop ;
end Q5L;
d2l0aCBBZGEuVGV4dF9JTzsgdXNlIEFkYS5UZXh0X0lPOwp3aXRoIEFkYS5JbnRlZ2VyX1RleHRfSU87IHVzZSBBZGEuSW50ZWdlcl9U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IGZvciBKIGluIDEgLi4gUSBsb29wCiAgICAgICAgICAgIFB1dChJbnRlZ2VyJ0ltYWdlKEMoSSwgSikpICYgIiAiKTsKICAgICAgICBlbmQgbG9vcDsKICAgICAgICBOZXdfTGluZTsgIC0tIE5vdmEgbGluaGEgYXDDs3MgY2FkYSBsaW5oYSBkYSBtYXRyaXoKICAgIGVuZCBsb29wOwplbmQgUTVMOwo=
stdout
Digite o número de linhas da matriz A (m): Digite o número de colunas da matriz A (n): Digite os elementos da matriz A:
Elemento ( 1, 1): Elemento ( 1, 2): Elemento ( 2, 1): Elemento ( 2, 2): Digite o número de linhas da matriz B (p): Digite o número de colunas da matriz B (q): Digite os elementos da matriz B:
Elemento ( 1, 1): Elemento ( 1, 2): Elemento ( 2, 1): Elemento ( 2, 2): A matriz C = A * B é:
3 5
6 7