Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: PiroskY en 17 Octubre 2010, 01:54 am



Título: [C++] Invertir matriz verticalmente
Publicado por: PiroskY en 17 Octubre 2010, 01:54 am
Código
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.    int mat[4][4],x,i,aux;
  7.  
  8.    //cargo matriz
  9.    for (x=0;x<4;x++)
  10.        cout << "Fila numero " << x+1 << endl;
  11.        for (i=0;i<4;i++)
  12.            cin >> mat[x][i];
  13.  
  14.    //invierto verticalmente
  15.    for (x=0;x<2;x++)
  16.        for (i=0;i<4;i++)
  17.        {
  18.            aux = mat[x][i];
  19.            mat[x][i] = mat[3-x][i];
  20.            mat[3-x][i] = aux;
  21.        }
  22.  
  23.    //muestro matriz
  24.    for (x=0;x<4;x++)
  25.        cout << endl;
  26.        for (i=0;i<4;i++)
  27.            cout << mat[x][i] << " ";
  28. return 0;
  29. }
  30.  

si la matriz es:

1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

me la deja como

7 6 5 4
6 5 4 3
5 4 3 2
4 3 2 1

Cuando deberia ser:

4 5 6 7
3 4 5 6
2 3 4 5
1 2 3 4

O sea, que me la invirte vertical y horizontalmente, pero no entiendo por que
Ademas de que no hace caso al endl, donde muestro la matriz
Alguien me dice en que me equivoco?


EDITO:

Reinicie pc y funciona perfectamente
No se que pasaba