Advertisement
Miketo_prog

Matriz invertida

May 12th, 2020 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     const int filMax=10,
  7.               colMax=10;
  8.     int filUser, colUser;
  9.     int matrizOrig[filMax][colMax];
  10.     int matrizInv[filMax][colMax];
  11.    
  12.     //Pedimos el tamaño de la matriz original
  13.     do{
  14.         cout<<"El tamaño maximo de la matriz solo puede ser de "<<filMax<<" filas por "<<colMax<<" columnas."<<endl;
  15.         cout<<"Que tamaño deseas tu?\n";
  16.         cout<<"Filas: ";
  17.         cin>>filUser;
  18.         cout<<"Columnas: ";
  19.         cin>>colUser;
  20.        
  21.     } while((filUser>=filMax)&&(colUser>=colMax));
  22.    
  23.     cout<<"\n\n\n";
  24.     cout<<"Captura la matriz\n\n";
  25.    
  26.     //Llenamos la matriz original por usuario
  27.     for(int i=0; i<filUser; i++)
  28.         for(int j=0; j<colUser; j++){
  29.             cout<<"Introduce la posicion ("<<(i+1)<<")("<<(j+1)<<"): ";
  30.             cin>>matrizOrig[i][j];
  31.         }
  32.    
  33.    
  34.     //Invertimos las filas de la matrizOrig
  35.     for(int i=0, m=(filUser-1); i<filUser; i++, m--)
  36.         for(int j=0; j<colUser; j++)
  37.             matrizInv[m][j]=matrizOrig[i][j];
  38.    
  39.    
  40.     //Linea de separacion
  41.     cout<<"\n\n";
  42.     for(int i=0; i<30; i++)
  43.         cout<<"- ";
  44.     cout<<"\n\n";
  45.        
  46.    
  47.     //Imprimimos la matriz original
  48.     cout<<"MATRIZ ORIGINAL\n\n";
  49.     for(int i=0; i<filUser; i++){
  50.         for(int j=0; j<colUser; j++)
  51.             cout<<matrizOrig[i][j]<<" ";
  52.         cout<<endl;
  53.     }
  54.    
  55.    
  56.     //Linea de separacion
  57.     cout<<"\n\n";
  58.     for(int i=0; i<30; i++)
  59.         cout<<"- ";
  60.     cout<<"\n\n";
  61.    
  62.    
  63.     //Imprimimos la matriz invertida
  64.     cout<<"MATRIZ INVERTIDA\n\n";
  65.     for(int i=0; i<filUser; i++){
  66.         for(int j=0; j<colUser; j++)
  67.             cout<<matrizInv[i][j]<<" ";
  68.         cout<<endl;
  69.     }
  70.    
  71.    
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement