Código
Fuente
class operaciones_matrices_completa
{ static void
mostrar (int a [] [], int n, int m)
{ int i, j;
for (i = 1
; i <= m ; i++)
{
for (j
= 1 ; j <= n ; j++)
System.out.print (a [i] [j] + " ");
System.out.println ();
}
}
static void
leer (int a [] [], int n, int m)
{ int i, j;
for (i = 1
; i <= m ; i++)
{
for (j
= 1 ; j <= n ; j++)
a
[i] [j] = Leer.datoInt ();
}
}
static void
suma (int a [] [], int b [] [], int n, int m)
{
int i, j,
sum = 0;
for (i = 1
; i <= m ; i++)
{
for (j
= 1 ; j <= n ; j++)
{
sum = a [i] [j] + b [i] [j];
System.out.print (sum + " ");
}
System.out.println ();
}
}
static void
resta (int a [] [], int b [] [], int n, int m)
{
int i, j,
res = 0;
for (i = 1 ; i <= m ; i++)
{
for (j
= 1 ; j <= n ; j++)
{
res
= a [i] [j] - b [i] [j];
System.out.print (res + " ");
}
System.out.println ();
}
} static void multi (int a [] [], int b [] [],
int c [] [], int n, int m)
{ int i, j, mul
= 1, sum = 0;
for (i = 1
; i <= m ; i++)
{
for (j
= 1 ; j <= n ; j++)
{
c
[i] [j] = 0;
for
(int k = 1 ; k <= n ; k++)
{
c [i]
[j] += a [i] [k] * b [k] [j];
}
}
}
}
public static
void main (String [] args)
{ int i, j, k, l, m = 0, n = 0, opc;
int a [] []
= new int [50] [50];
int b [] []
= new int [50] [50];
int c [] []
= new int [50] [50];
int u [] []
= new int [50] [50];
int inv []
[] = new int [50] [50];
do{
System.out.println ("Opciones ");
System.out.println ("1.- Introducir matrices A y B ");
System.out.println ("2.- A + B
");
System.out.println ("3.- A - B
");
System.out.println ("4.- A * B
");
System.out.println ("0.- SALIR
");
System.out.println
("Elige una opcion ");
opc =
Leer.datoInt ();
switch
(opc)
{
case 1:
System.out.println ("Introduzca el valor de n :");
n = Leer.datoInt ();
System.out.println
("Introduzca el valor de m :");
m = Leer.datoInt ();
System.out.println ("Introduciendo los valores de la matriz
A");
leer (a, n, m);
System.out.println ("Introduciendo los valores de la matriz
B");
leer (b, n, m);
System.out.println ("matriz A");
mostrar (a, n, m);
System.out.println ("matriz B");
mostrar (b, n, m);
break;
case 2:
System.out.println ("Matriz A ");
mostrar (a, n, m);
System.out.println ("Matriz B ");
mostrar (b, n, m);
System.out.println ("Suma del matriz A+B");
suma (a, b, n, m);
break;
case 3:
System.out.println ("Matriz A ");
mostrar (a, n, m);
System.out.println ("Matriz B ");
mostrar (b, n, m);
System.out.println ("Resta del matriz A-B");
resta (a, b, n, m);
break;
case 4:
System.out.println ("Matriz A
");
mostrar (a, n, m);
System.out.println ("Matriz B ");
mostrar (b, n, m);
System.out.println ("Producto del matriz AxB");
multi (a, b, c, n, m);
mostrar (c, n, m);
break;
}
}
while (opc
!= 0);
}
}

