#include<math.h>
using namespace std;
const int n=2,m=2;
int i,j,suma, prom, ;
int matriz[n][m],a[n][m],b[n][m];
int leermatriz();
int sumaelementos();
int impresion();
int identidad();
int central();
int leomatriza();
int leomatrizb();
int sumamatrices();
float promediomatriz();
int contarelementos();
int transpuesta();
int main ()
{//1)DECLARACION
int opcion;
do
{
cout<<"*********MENU DE MATRICES**********\n\n";
cout<<" 1)LECTURA UNA MATRIZ \n";
cout<<" 2)IMPRESION O ESCRITURA DE LA MATRIZ \n";
cout<<" 3) MATRIZ identidad \n";
cout<<" 4)elementos centrales\n";
cout<<" 5) lectura de matriz A \n";
cout<<" 6)lectrura de matrizB \n";
cout<<" 7)suma de matrices \n";
cout<<" 8)suman \n";
cout<<" 9)promedio de la matriz \n";
cout<<" 10)contar los elementos que estan sob y bajo el prom\n";
cout<<" 11)la transpuesta del elemento es \n";
cout<<" DIGITE <0> PARA SALIR \n\n";
cout<<"*************\n\n";
cout<<" ELIJA UNA OPCION : "; cin>>opcion;
//2)ASIGNACION
switch (opcion)
{
case 1:
{
cout<<"leer elementos de una matriz\n";
leermatriz();//invocacion
} //FIN DEL CASO 1
break;
case 2:
{
cout<<"impresion o escritura de una matriz\n";
cout<<"los elementos son\n";
impresion();
} //FIN DEL CASO 2
break;
case 3:
{
cout<<"matriz identidad\n";
identidad();
//FIN DEL CASO 3
}
break;
case 4:
{
cout<<"elementos centrales\n";
central();
}
break;
case 5:
{
cout<<"lectura de la matriz A[i][j]\n";
leomatriza();
}
break;
case 6:
{
cout<<"lectura de la matriz B[i][j]\n";
leomatrizb();
}
break;
case 7:
{
cout<<"suma de matrices A y B \n";
sumamatrices();
}
break;
case 8:
{
cout<<"suma de elementos\n";
sumaelementos();
}break;
case 9:
{
cout<<"promedio de la matriz \n";
promediomatriz();
cout<<"********************************* \n";
}break;
case 10:
{
cout<<"contar los elementos que estan sob y bajo el prom \n";
contarelementos();
cout<<"********************************* \n";
}break;
case 11:
{
cout<<"la transpuesta del elemento es:>>-- \n";
transpuesta();
cout<<"********************************* \n";
}break;
}
}// FIN DE SWITCH }
while (opcion !=0);
cout<<endl;cout<<"\n";
system("pause");
return 0;
}//FIN DEL PROGRAMA
int leermatriz()
{
for(i=1; i<=n; i++)
for(j=1; j<=m; j++)
{
cout<<"ingrese los elementos \n";
cout<<"M["<<i<<"] M["<<j<<"]:";
cin>>matriz[i][j];
}
}
int sumaelementos()
{
suma=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
suma=suma+matriz[i][j];
}
cout<<"la suma de los elementos es ="<<suma<<endl;
}
int impresion()
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cout<<"M["<<i<<"] M["<<j<<"]:"<<matriz[i][j]<<endl;
}
}
int identidad()
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cout<<"M["<<i<<"] M["<<j<<"]:"<<matriz[i][j]<<endl;
}
}
int central()
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
if(i==j)
cout<<"M["<<i<<"] M["<<j<<"]:"<<matriz[i][j]<<endl;
}
}
int leomatriza()
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cout<<"ingrese los elementos \n";
cout<<"A["<<i<<"] A["<<j<<"]:";
cin>>a[i][j];
}
}
int leomatrizb()
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cout<<"ingrese los elementos \n";
cout<<"B["<<i<<"] B["<<j<<"]:";
cin>>b[i][j];
}
}
int sumamatrices()
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
matriz[i][j]= a[i][j]+b[i][j];
}
}
float promediomatriz()
{
suma=0;
for (i=1; i<=n ; i++)
for (j=1; j<=n ; i++)
{
suma=suma+matriz[i][j];
}
prom = suma/(n*m);
cout<<"El promedio de la matriz "<<prom;
}
int contarelementos()
{
int M, m;
M=0;
m=0;
for (i=1; i<=n ; i++)
for (j=1; j<=n ; i++)
{
if (matriz[i][j]>prom)
M=M+1;
if(matriz[i][j]<prom)
m=m+1;
}
cout<<"Existen "<<M<<"Elementos mayores"<<endl;
cout<<"Existen "<<m<<"Elementos menores"<<endl;
}
int transpuesta()
{
for (i=1; i<=n ; i++)
for (j=1; j<=m ; i++)
{
matriz[i][j] = matriz[j][i];
}
cout<<"la transpuesta---.. "<<matriz[i][j]<<endl;
}
No hay comentarios:
Publicar un comentario