Duda sonre array en zigzag

(1/1)

vladi89:
[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
const int kfila = 3;
       const int kcolumna = 3;
 
       int[,] matriz = new int[kfila, kcolumna];
 
 
 
       void leermatriz(int[,] matriz)
       {
           int i, j;
 
           for (i = 0; i < matriz.GetLength(0); i++)
               for (j = 0; j < matriz.GetLength(1); j++)
                   matriz[i, j] = int.Parse(InputBox("elemento[" + i + " , " + j + "]"));
       }
       string mostrarmatriz(int[,] matriz)
       {
           int i, j;
           string texto;
           texto = "Los valores de la matriz son:\n";
 
           for (j = 0; j < matriz.GetLength(1); j++)
           {
 
               for (i = 0; i < matriz.GetLength(0); i++)
                   for (i = matriz.GetLength(0) - 1; i >= 0; i--)
                       texto = texto + matriz[i, j] + ", ";
               texto = texto + "\n"; // Retorno de carro al terminar cada fila
           }
           return texto;
       }

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

Navegación

[0] Índice de Mensajes