with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Q5N is
-- Definindo o tipo para a matriz
type Matrix is array (1 .. 3, 1 .. 3) of Integer; -- Matrizes 3x3
A, B, C : Matrix; -- Matrizes A, B e C
Is_Inverse : Boolean := True; -- Flag para verificar se são inversas
begin
-- Entrada da matriz A
Put_Line("Digite os elementos da matriz A (3x3):");
for I in 1 .. 3 loop
for J in 1 .. 3 loop
Put("Elemento (" & Integer'Image(I) & ", " & Integer'Image(J) & "): ");
Get(A(I, J));
end loop;
end loop;
-- Entrada da matriz B
Put_Line("Digite os elementos da matriz B (3x3):");
for I in 1 .. 3 loop
for J in 1 .. 3 loop
Put("Elemento (" & Integer'Image(I) & ", " & Integer'Image(J) & "): ");
Get(B(I, J));
end loop;
end loop;
-- Calculando a multiplicação C = A * B
for I in 1 .. 3 loop
for J in 1 .. 3 loop
C(I, J) := 0; -- Inicializando C
for K in 1 .. 3 loop
C(I, J) := C(I, J) + A(I, K) * B(K, J);
end loop;
end loop;
end loop;
-- Verificando se C é a matriz identidade
for I in 1 .. 3 loop
for J in 1 .. 3 loop
if I = J then
if C(I, J) /= 1 then
Is_Inverse := False;
end if;
else
if C(I, J) /= 0 then
Is_Inverse := False;
end if;
end if;
end loop;
end loop;
-- Resultado
if Is_Inverse then
Put_Line("A matriz B é a inversa da matriz A.");
else
Put_Line("A matriz B não é a inversa da matriz A.");
end if;
end Q5N;
d2l0aCBBZGEuVGV4dF9JTzsgdXNlIEFkYS5UZXh0X0lPOwp3aXRoIEFkYS5JbnRlZ2VyX1RleHRfSU87IHVzZSBBZGEuSW50ZWdlcl9UZXh0X0lPOwoKcHJvY2VkdXJlIFE1TiBpcwogICAgLS0gRGVmaW5pbmRvIG8gdGlwbyBwYXJhIGEgbWF0cml6CiAgICB0eXBlIE1hdHJpeCBpcyBhcnJheSAoMSAuLiAzLCAxIC4uIDMpIG9mIEludGVnZXI7ICAtLSBNYXRyaXplcyAzeDM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yBDCiAgICAgICAgICAgIGZvciBLIGluIDEgLi4gMyBsb29wCiAgICAgICAgICAgICAgICBDKEksIEopIDo9IEMoSSwgSikgKyBBKEksIEspICogQihLLCBKKTsKICAgICAgICAgICAgZW5kIGxvb3A7CiAgICAgICAgZW5kIGxvb3A7CiAgICBlbmQgbG9vcDsKCiAgICAtLSBWZXJpZmljYW5kbyBzZSBDIMOpIGEgbWF0cml6IGlkZW50aWRhZGUKICAgIGZvciBJIGluIDEgLi4gMyBsb29wCiAgICAgICAgZm9yIEogaW4gMSAuLiAzIGxvb3AKICAgICAgICAgICAgaWYgSSA9IEogdGhlbgogICAgICAgICAgICAgICAgaWYgQyhJLCBKKSAvPSAxIHRoZW4KICAgICAgICAgICAgICAgICAgICBJc19JbnZlcnNlIDo9IEZhbHNlOwogICAgICAgICAgICAgICAgZW5kIGlmOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBpZiBDKEksIEopIC89IDAgdGhlbgogICAgICAgICAgICAgICAgICAgIElzX0ludmVyc2UgOj0gRmFsc2U7CiAgICAgICAgICAgICAgICBlbmQgaWY7CiAgICAgICAgICAgIGVuZCBpZjsKICAgICAgICBlbmQgbG9vcDsKICAgIGVuZCBsb29wOwoKICAgIC0tIFJlc3VsdGFkbwogICAgaWYgSXNfSW52ZXJzZSB0aGVuCiAgICAgICAgUHV0X0xpbmUoIkEgbWF0cml6IEIgw6kgYSBpbnZlcnNhIGRhIG1hdHJpeiBBLiIpOwogICAgZWxzZQogICAgICAgIFB1dF9MaW5lKCJBIG1hdHJpeiBCIG7Do28gw6kgYSBpbnZlcnNhIGRhIG1hdHJpeiBBLiIpOwogICAgZW5kIGlmOwplbmQgUTVOOwo=
Digite os elementos da matriz A (3x3):
Elemento ( 1, 1): Elemento ( 1, 2): Elemento ( 1, 3): Elemento ( 2, 1): Elemento ( 2, 2): Elemento ( 2, 3): Elemento ( 3, 1): Elemento ( 3, 2): Elemento ( 3, 3): Digite os elementos da matriz B (3x3):
Elemento ( 1, 1): Elemento ( 1, 2): Elemento ( 1, 3): Elemento ( 2, 1): Elemento ( 2, 2): Elemento ( 2, 3): Elemento ( 3, 1): Elemento ( 3, 2): Elemento ( 3, 3): A matriz B é a inversa da matriz A.