ISMAEL MARIN VERA
/* ESTE PROGRAMA NOS PERMITE ELEGIR ENTRE SUMAR O MULTIPLICAR DOS MATRICES O CALCULAR LA TRANSPUESTA DE UNA MATRIZ */
// OPERACIONES CON MATRICES
#include <iostream>
#include <stdlib.h>
#define DIM 200
using namespace std;
void SUMA();
void PRODUCTO();
void TRASPUESTA();
int main ()
{
int z;
cout << ” OPCIONES \n”;
cout << ” 1 \t SUMA:” << endl;
cout << ” 2 \t PRODUCTO: ” << endl;
cout << ” 3 \t TRANSPUESTA: ” << endl;
do {
cout << ” SELECCIONE ENTRE UNA DE LAS OPCIONES: \n”;
cin >> z;
} while (z<1 || z>3);
if (z==1){
SUMA();
cout << ” la suma de las matrices es: ” << sumita << endl;
}
if (z==2){
PRODUCTO();
}
if (z==3){
TRASPUESTA();
cout << ” la transpuesta de la matriz introducida es: ” << transpuestita<< endl;
}
return 0;
}
void SUMA()
{
int i, j;
int n;
int M[DIM][DIM];
int Z[DIM][DIM];
int SUMA[DIM][DIM];
do{
cout << ” Introduce la dimension de la matriz: \n”;
cin >> n;
} while(n<0 || n> DIM);
cout <<” LECTURA MATRIZ M: “<< endl;
cout << ” Introduce los componentes de a matriz: \n”;
for(i=0;i<n;i++){
for (j=0; j<n;j++){
cin >> M[i][j];
}
}
cout << endl;
cout <<” LECTURA MATRIZ Z: “<< endl;
cout << ” Introduce los componentes de la matriz: \n”;
for(i=0;i<n;i++){
for (j=0; j<n;j++){
cin >> Z[i][j];
}
}
cout << endl;
cout << ” MUESTRA MATRIZ M: \n”;
for(i=0;i<n;i++){
for (j=0; j<n;j++){
cout << M[i][j] << “\t”;
}
cout << endl;
}
cout << endl << endl;
cout << ” MUESTRA MATRIZ Z: \n”;
for(i=0;i<n;i++){
for (j=0; j<n;j++){
cout << Z[i][j] << “\t”;
}
cout << endl;
}
cout << endl << endl;
cout << ” MATRIZ SUMA: \n”;
for(i=0;i<n;i++){
for (j=0; j<n;j++){
SUMA[i][j]=M[i][j]+Z[i][j];
cout << SUMA[i][j] << “\t”;
}
cout << endl;
}
cout << endl << endl;
return;
}
void TRASPUESTA()
{
int n;
int M[DIM][DIM];
int TRASPUESTA[DIM][DIM];
int i, j;
int a=0;
int b =0;
do{
cout << ” Introduce la dimension de la matriz : \n”;
cin >> n;
} while (n<0 || n>DIM);
cout << ” LECTURA MATRIZ M: \n” ;
cout << ” Inttoduce los componentes de la matriz: \n”;
for (i=0; i<n;i++){
for (j=0; j<n; j++){
cin >> M[i][j];
}
}
cout << endl << endl;
cout << ” MUESTRA MATRIZ M \n” ;
for (i=0; i<n;i++){
for (j=0; j<n; j++){
cout << M[i][j] << “\t”;
}
cout << endl;
}
cout << endl << endl;
cout << ” MATRIZ TRASPUESTA: \n\n”;
for(i=0; i<n; i++){
for (j=0; j<n; j++){
a=i;
b=j;
TRASPUESTA[i][j]=M[b][a];
}
}
for(i=0;i<n;i++){
for (j=0; j<n ; j++){
cout << TRASPUESTA[i][j] << “\t” ;
}
cout << endl;
}
return;
}
void PRODUCTO()
{
int n;
int i, j, z;
int M[DIM][DIM];
int Z[DIM][DIM];
int PRODUCTO [DIM][DIM];
do{
cout << ” Introduce la dimension de las matrices: \n\n” << endl;
cin >> n;
} while (n<0 || n > DIM);
cout << ” LECTURA MATRIZ M: ” << endl << endl;
cout << ” Introduce los valores de la matriz: ” << endl;
for (i=0; i<n;i++){
for(j=0;j<n;j++){
cin >> M[i][j];
}
}
cout << endl << endl;
cout << ” LECTURA MATRIZ Z: ” << endl << endl;
cout << ” Introduce los valores de la matriz: ” << endl;
for (i=0; i<n;i++){
for(j=0;j<n;j++){
cin >> Z[i][j];
}
}
cout << endl << endl;
cout << ” MUESTRA MATRIZ M: ” << endl << endl;
for (i=0; i<n;i++){
for (j=0; j<n; j++){
cout << M[i][j] << “\t”;
}
cout << endl;
}
cout << endl << endl;
cout << ” MUESTRA MATRIZ Z: ” << endl << endl;
for (i=0; i<n;i++){
for (j=0; j<n; j++){
cout << Z[i][j] << “\t”;
}
cout << endl;
}
cout << ” PRODUCTO MATRICES: \n”;
for (i=0; i<n;i++){
for (j=0; j<n; j++){
PRODUCTO[i][j]=0;
}
}
for (i=0; i<n;i++){
for (j=0; j<n; j++){
for(z=0; z<n; z++){
PRODUCTO[i][j] +=M[i][z]*Z[z][j];
}
}
}
for (i=0; i<n;i++){
for (j=0; j<n; j++){
cout << PRODUCTO[i][j] << “\t”;
}
cout << endl;
}
return;
}
Anuncios