Tema: Matrices
# include <iostream>
# include <math.h>
# include <cstdlib>
using namespace std;
int Opcion;
int i,j,z,M[3][3], SUMA, DET;
int C[5][5], A[5][5], B[5][5], D[3][3], E[3][3], F[3][3];
void ASIGNAR_M(), MOSTRAR_M(), PROMEDIO_M(),SUMAR_MATR(), DETERMINANTE_M(), PRODUCTO_M(),TRANSPUESTA_M();
float PROM;
int main()
{
do
{
cout << "\n MENU DE FUNCIONES"<< endl;
cout << " ----------------------------"<< endl;
cout << " [1] ASIGNAR DATOS A LA MATRIZ"<< endl;
cout << " [2] MOSTRAR DATOS DE LA MATRIZ"<< endl;
cout << " [3] PROMEDIO DE LOS ELEMENTOS DE UNA MATRIZ "<< endl;
cout << " [4] SUMA DE DOS MATRICES "<< endl;
cout << " [5] DETERMINANTE DE UNA MATRIZ 3X3 "<< endl;
cout << " [6] PRODUCTO DE DOS MATRICES "<< endl;
cout << " [7] TRANSPUESTA DE UNA MATRIZ "<< endl;
cout << "\n INGRESE UNA OPCION <> 0 : ";
cin>>Opcion;
switch (Opcion)
{
case 1:
{
cout << "\n ASIGNAR DATOS A LA MATRIZ"<< endl;
cout << " ----------------------------"<< endl;
ASIGNAR_M();
} break;
case 2:
{
cout << "\n MOSTRAR DATOS DE LA MATRIZ"<< endl;
cout << " ----------------------------"<< endl;
MOSTRAR_M();
} break;
case 3:
{
cout << "\n PROMEDIO DE LOS ELEMENTOS DE UNA MATRIZ"<< endl;
cout << " ----------------------------"<< endl;
PROMEDIO_M();
} break;
case 4:
{
cout << "\n SUMA DE DOS MATRICES"<< endl;
cout << " ----------------------------"<< endl;
SUMAR_MATR();
} break;
case 5:
{
cout << "\n SUMA DE DOS MATRICES"<< endl;
cout << " ----------------------------"<< endl;
DETERMINANTE_M();
} break;
case 6:
{
cout << "\n PRODUCTO DE DOS MATRICES"<< endl;
cout << " ----------------------------"<< endl;
PRODUCTO_M();
} break;
case 7:
{
cout << "\n TRANSPUESTA DE UNA MATRIZ"<< endl;
cout << " ----------------------------"<< endl;
TRANSPUESTA_M();
} break;
}
} while(Opcion !=0);
}
void ASIGNAR_M()
{
cout<<"Ingrese los elementos de la matriz M[3][3]"<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
cout<<"M["<<i<<"]["<<j<<"] = "; cin>>M[i][j];
}
}
void MOSTRAR_M()
{
cout<<"Mostrar los elementos de la matriz M[3][3]"<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
cout<<"M["<<i<<"]["<<j<<"] = "<<M[i][j]<<endl;
}
}
void PROMEDIO_M()
{
SUMA = 0;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
SUMA = SUMA + M[i][j];
}
PROM = SUMA/9;
cout<<SUMA<<endl;
cout<<"El promedio de los elementos de la matriz M[3][3]="<<PROM<<endl;
}
void SUMAR_MATR()
{
cout<<"\n Ingrese los elementos de la matriz A[5][5] y B[5][5]"<<endl;
for(i=1; i<=5;i++)
for(j=1; j<=5;j++)
{
A[i][j]=rand()%30;
B[i][j]=rand()%30;
}
//MOSTRAR
cout<<"Mostrar los elementos de la matriz A[5][5]:"<<endl;
for(i=1; i<=5;i++)
for(j=1; j<=5;j++)
{
cout<<"A["<<i<<"]["<<j<<"] = "<<A[i][j]<<endl;
}
cout<<endl;
cout<<"\n Mostrar los elementos de la matriz B[5][5]:"<<endl;
for(i=1; i<=5;i++)
for(j=1; j<=5;j++)
{
cout<<"B["<<i<<"]["<<j<<"] = "<<B[i][j]<<endl;
}
// PROCESO DE SUMA DE DOS MATRICES
for(i=1; i<=5;i++)
for(j=1; j<=5;j++)
{
C[i][j] = A[i][j] + B[i][j];
}
cout<<"\n Mostrar los elementos de la matriz C[5][5]:"<<endl;
for(i=1; i<=5;i++)
for(j=1; j<=5;j++)
{
cout<<"C["<<i<<"]["<<j<<"] = "<<C[i][j]<<endl;
}
}
void DETERMINANTE_M()
{
cout<<"Ingrese los elementos de la matriz D[3][3]"<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
D[i][j]=rand()%30;
//MOSTRAR
}
cout<<"Mostrar los elementos de la matriz D[3][3]"<<endl;
for(i=1; i<=3;i++){
for(j=1; j<=3;j++)
{
cout<<" "<<D[i][j]<<" ";
}
cout<<"\n";
}
DET = D[1][1]*(D[2][2]*D[3][3]-D[2][3]*D[3][2]) - D[1][2]*(D[2][1]*D[3][3]-D[2][3]*D[3][1]) + D[1][3]*(D[2][1]*D[3][2]-D[2][2]*D[3][1]);
cout<<"La determinante de la matriz D[3][3] es: "<<DET<<endl;
}
void PRODUCTO_M()
{
cout<<"\n Ingrese los elementos de la matriz D[3][3] y E[3][3]"<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
D[i][j]=rand()%30;
E[i][j]=rand()%30;
}
//MOSTRAR
cout<<"Mostrar los elementos de la matriz D[3][3]:"<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
cout<<"D["<<i<<"]["<<j<<"] = "<<D[i][j]<<endl;
}
cout<<endl;
cout<<"\n Mostrar los elementos de la matriz E[5][5]:"<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
cout<<"E["<<i<<"]["<<j<<"] = "<<E[i][j]<<endl;
}
//PROCESO DE PRODUCTO DE DOS MATRICES
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
F[i][j]=0;
}
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
for(z=1; z<=3;z++)
{
F[i][j]= F[i][j] + D[i][z]*E[z][j];
}
cout<<endl;
cout<<"\n Mostrar los elementos de la matriz E[5][5]:"<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
cout<<"F["<<i<<"]["<<j<<"] = "<<F[i][j]<<endl;
}
}
void TRANSPUESTA_M()
{
cout<<"\n Ingrese los elementos de la matriz D[3][3] "<<endl;
for(i=1; i<=3;i++)
for(j=1; j<=3;j++)
{
D[i][j]=rand()%30;
}
//MOSTRAR
cout<<" Mostrar los elementos de la matriz D[3][3]:"<<endl;
for(i=1; i<=3;i++){
for(j=1; j<=3;j++)
{
cout<<" "<<D[i][j]<<" ";
}
cout<<"\n";
}
// PROCESO TRANSPUESTA DE UNA MATRIZ
cout<<endl;
cout<<" LA TRANSPUESTA DE LA MATRIZ D[3][3]:"<<endl;
for(i=1; i<=3;i++){
for(j=1; j<=3;j++)
{
cout<<" "<<D[j][i]<<" ";
}
cout<<"\n";
}
}


