sábado, 17 de enero de 2015

LAB 3

// ESTRUCTURA EN BLANCO
#include<iostream>
#include<math.h>
using namespace std;

int a, b, c, n, R1, R2, R3, Req, L, C, f;
double Fx, P, fo;
// ZONA DE DECLARACION DE LOS VECTORES
const int TAM_N=4, TAM_M=4;
int suma, i, j, Elemento, max, min, Matriz[TAM_N][TAM_M], A[TAM_N][TAM_M], B[TAM_N][TAM_M];

int main ()
 {
    //1)DECLARACION
  int opcion;
  do
  { // INICIO DEL DO - WHILE
  cout<<"********* MENU DE MATRICES *************************\n\n";
  cout<<" 1) LECTURA UNA MATRIZ \n";
  cout<<" 2) IMPRESION O ESCRITURA O VISULAIZACION DE LA MATRIZ \n";
  cout<<" 3) PROCESAR EL MAXIMO DE LOS ELEMENTOS DE LA MATRIZ\n";
  cout<<" 4) PROCESAR EL MINIMO DE LOS ELEMENTOS DE LA MATRIZ  \n";
  cout<<" 5) SUMA DE ELEMENTOS DE LA MATRIZ \n";
  cout<<" 6) SUMA DE MATRICES A + B \n";
  cout<<" 7) DIAGONAL DE UNA MATRIZ  \n";
  cout<<" 8) SUMA DE LAS FILAS DE LA MATRIZ  \n"; 
  cout<<" 9) SUMA DE LAS COLUMNAS FILAS DE LA MATRIZ  \n\n"; 
  cout<<"          DIGITE <0> PARA SALIR \n\n";
  cout<<"*************************************************\n\n";
  cout<<"   ELIJA UNA OPCION : "; cin>>opcion;
    //2)ASIGNACION
    switch (opcion)
    {
    case 1:
      {
       cout<<"*******  LECTURA DE VECTORES *********************\n\n";

       for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
       {
       cout<<"INGRESE EL ELEMENTO M[ "<<i<<","<<j<<" ] = "; cin>>Matriz[i][j];        
       }
       cout<<endl;
       cout<<"**********************************************\n\n";
     } //FIN DEL CASO 1
     break;     

    case 2:
      {
       cout<<"*******  IMPRESION O ESCRITURA DE LA MATRIZ *********************\n\n";

       for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
       {
       cout<<"ELEMENTO M[ "<<i<<","<<j<<" ] = "<<Matriz[i][j]<<endl;        
       }
       cout<<endl;
       cout<<"**********************************************\n\n";
     } //FIN DEL CASO 1
     break;     
    
  case 3:
    {  
     cout<<"******* PROCESAR EL MAXIMO DE LOS ELEMENTOS *********************\n\n";
     int max=0;
     for (i=1; i<=TAM_N; i++)
       for (j=1; j<=TAM_M; j++)    
        {
         if(Matriz[i][j]>max)
           max = Matriz[i][j];
        }
    // RESULTADO
     cout <<" EL MAXIMO DE LOS ELEMENTOS DE LA MATRIZ ES: "<<max;
     cout<<endl; 
     cout<<"**********************************************\n\n";
    } //FIN DEL CASO 2
    break;

    case 4:
      {
       cout<<"******* PROCESAR EL MINIMO ******\n\n";
       int min=100;
       for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
        {
         if(Matriz[i][j]<min)
         min = Matriz[i][j];
        }
      // RESULTADO
     cout <<" EL MINIMO DE LOS ELEMENTOS DE LA MATRIZ ES: "<<min;
     cout<<endl; 
     cout<<"**********************************************\n\n";
      } //FIN DEL CASO 3
      break;
     
    case 5:
     {
      cout<<"******* SUMA DE ELEMENTOS DE LA MATRIZ ******\n\n";    
//      int
    // int  suma;    
     suma = 0;
      for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
        {
          suma = suma + Matriz[i][j];
        }
      cout<<"---------------------------------- \n ";
      cout<<"LA SUMA DE LOS ELEMENTOS DE LA MATRIZ ES: "<< suma << endl;
      cout << endl;
      cout<<"********************************\n\n";    
            
     } //FIN DEL CASO 4
     break;
    
    case 6:
     {
      cout<<"******* SUMA DE MATRICES ************************\n\n";
      for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
       {
       cout<<"INGRESE EL ELEMENTO A[ "<<i<<","<<j<<" ] = "; cin>>A[i][j];        
       }
      for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
       {
       cout<<"INGRESE EL ELEMENTO B[ "<<i<<","<<j<<" ] = "; cin>>B[i][j];        
       }
     // PROCESO
      for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
       {
        Matriz[i][j] = A[i][j] + B[i][j];
       }    
     // resultado
       for (i=1; i<=TAM_N; i++)
        for (j=1; j<=TAM_M; j++)
       {
       cout<<"INGRESE EL ELEMENTO M[ "<<i<<","<<j<<" ] = "<<Matriz[i][j]<<endl;        
       }
       cout<<endl;
      cout << endl;
      cout<<"*************************************\n\n";     
     } //FIN DEL CASO 6
     break;

    case 7:
     {
      cout<<"******* DIAGONAL DE LA MATRIZ ******\n\n";
      suma = 0;
      c = 0;
      int max = 0, min = 100;
      for (i=1; i<=TAM_N; i++)
       for (j=1; j<=TAM_M; j++)
       {
         if (i==j)
         {
          cout<<"ELEMENTO CENTRAL M[ "<<i<<","<<j<<" ] = "<<Matriz[i][j]<<endl;    
          c = c + 1;
          suma = suma + Matriz[i][j]; 
          if (Matriz[i][j]>max)
             max = Matriz[i][j];
          if (Matriz[i][j]<min)
             min = Matriz[i][j];            
         }
       }// primer for
       cout<<"LA SUMA DE LOS ELEMENTOS ES: "<<suma<<endl;
       cout<<"EL PROMEDIO ES: "<<suma/c<<endl;      
       cout<<"EL MAXIMO ES: "<<max<<endl;      
       cout<<"EL MINIMO ES: "<<min<<endl;             
      cout<< endl;                   
      cout<<"******************************************\n\n";
      cout<<endl;
     }      //FIN DEL CASO 7
     break;

    case 8:
     {
      cout<<"******* SUMA DE LAS FILAS DE LA MATRIZ *********\n\n";
    
      for (i=1; i<=TAM_N; i++)
      {
        cout<<"------------------ fila "<<i<<endl; 
        suma = 0;
       for (j=1; j<=TAM_M; j++)
       {
         if (i==i)
         {
          cout<<"ELEMENTO DE LA FILA i = "<<i<<" M[ "<<i<<","<<j<<" ] = "<<Matriz[i][j]<<endl;    
          suma = suma + Matriz[i][j]; 
         } // fin del if
       }// primer for
         cout<<endl; 
         cout<<"LA SUMA DE LOS ELEMENTOS DE LA FILA i= "<<i<<" es: "<<suma<<endl;      
       }//segundo for
      cout<<endl;          
      cout<<"******************************************\n\n";
      }      //FIN DEL CASO 7
     break;
    
    case 9:
     {
      cout<<"******* SUMA DE LAS COLUMNAS FILAS DE LA MATRIZ  *******\n\n";
      for (j=1; j<=TAM_M; j++)
      {
        cout<<"------------------ COLUMNA "<<j<<endl;   
        suma = 0;
       for (i=1; i<=TAM_N; i++)
       {
         if (j==j)
         {
          cout<<"ELEMENTO DE LA COLUMNA j = "<<j<<" M[ "<<j<<","<<j<<" ] = "<<Matriz[i][j]<<endl;    
          suma = suma + Matriz[i][j]; 
         } // fin del if
       }// primer for
         cout<<endl; 
         cout<<"LA SUMA DE LOS ELEMENTOS DE LA COLUMNA j= "<<j<<" es: "<<suma<<endl;      
       }//segundo for         
      cout<<endl;          
      cout<<"******************************************\n\n";
      cout<<endl;
      }      //FIN DEL CASO 7
     break;
        
}// FIN DE SWITCH
   
} // FIN DEL DO - WHILE
while (opcion !=0);

    cout<<endl;cout<<"\n";
    system("pause");
    return 0;
}//FIN DEL PROGRAMA


No hay comentarios.:

Publicar un comentario