Pregunta: | 67711 - COMO LLENAR UNA MATRIZ DE FORMA DIAGONAL. |
Autor: | Juan Carlos Moreno Martinez |
hola que tal, pues necesito llenar una matriz diagonalmente de n x m dados por el usuario, ejemplo una matriz de 2 x 4 debe imprimir: 1 2 4 6 3 5 7 8 o una de 3 x 5 1 2 4 7 10 3 5 8 11 13 6 9 12 14 15 solo llevo esto y no se si me sirva : static void Main(string[] args) { int n,m,k=1; Console.WriteLine("Ingresa el numero de filas de la matriz"); n=Int32.Parse(Console.ReadLine()); Console.WriteLine("Ingresa el numero de columnas de la matriz"); m=Int32.Parse(Console.ReadLine()); int[,] arreglo = new int[n,m]; for (int i = 0; i < n ; i++) { // recorremos filas for (int j = 0; j< m; j++) { // recorremos columnas arreglo[i, j] = k; k++; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) Console.Write(" " + arreglo[i, j]); Console.WriteLine(); } de antemano muchas gracias por su respuesta :) |