Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: vladi89 en 19 Enero 2016, 18:52 pm



Título: Duda sonre array en zigzag
Publicado por: vladi89 en 19 Enero 2016, 18:52 pm
[NOTA DEL MODERADOR]
1. Usa las etiquetas GeShi para isnertar código.
2. Publica las preguntas de programación en el subforo correspondiente.
Lee las reglas del foro.



Buenas a todos, aunque no sé si este tema iria aquí.

tengo una duda sobre un programa que imprima una matriz en zig zag así

Código:
1 10 11 20
2 9  12 19
3 8  13 18
4 7  14 17
5 6  15 16

de momento tengo esto pero estoy bloqueado, no se como darle la vuelta cada vez que llegue al final de una columna

Código
  1. const int kfila = 3;
  2.        const int kcolumna = 3;
  3.  
  4.        int[,] matriz = new int[kfila, kcolumna];
  5.  
  6.  
  7.  
  8.        void leermatriz(int[,] matriz)
  9.        {
  10.            int i, j;
  11.  
  12.            for (i = 0; i < matriz.GetLength(0); i++)
  13.                for (j = 0; j < matriz.GetLength(1); j++)
  14.                    matriz[i, j] = int.Parse(InputBox("elemento[" + i + " , " + j + "]"));
  15.        }
  16.        string mostrarmatriz(int[,] matriz)
  17.        {
  18.            int i, j;
  19.            string texto;
  20.            texto = "Los valores de la matriz son:\n";
  21.  
  22.            for (j = 0; j < matriz.GetLength(1); j++)
  23.            {
  24.  
  25.                for (i = 0; i < matriz.GetLength(0); i++)
  26.                    for (i = matriz.GetLength(0) - 1; i >= 0; i--)
  27.                        texto = texto + matriz[i, j] + ", ";
  28.                texto = texto + "\n"; // Retorno de carro al terminar cada fila
  29.            }
  30.            return texto;
  31.        }

Solo pido saber como le doy la vuelta para que continue en la columna siguiente, un saludo. y gracias