using System;
internal class Program
{
static void Main(string[] args)
{
// Matriz de valores definidos
int[,] matriz1 = { { -1, -2, -3 }, { 1, 5, 2 } };
Console.WriteLine("Manipulando arreglos bidimensionales");
Console.WriteLine("posicion [0][0] = " + matriz1[0, 0]);
Console.WriteLine("posicion [0][1] = " + matriz1[0, 1]);
Console.WriteLine("posicion [1][2] = " + matriz1[1, 2]);
// Matriz de 3x3 para ingresar valores
int[,] matriz2 = new int[3, 3];
Console.WriteLine("\n Vamos a insertar desde teclado");
LeerMatriz(matriz2);
// Matriz double
double[,] matriz3 = { { -8, -7, -6 }, { 8, 7, 6 } };
Console.WriteLine("\nManipulando otra matriz");
Console.WriteLine("posicion [0][0] = " + matriz3[0, 0]);
Console.WriteLine("posicion [0][1] = " + matriz3[0, 1]);
Console.WriteLine("posicion [1][1] = " + matriz3[1, 1]);
Console.WriteLine("posicion [1][2] = " + matriz3[1, 2]);
// Otra matriz vacía de 3x3
int[,] matriz4 = new int[3, 3];
Console.WriteLine("\n Vamos a insertar desde teclado en otra matriz");
LeerMatriz(matriz4);
}
// Método leer valores en una matriz
static void LeerMatriz(int[,] matriz)
{
for (int filas = 0; filas < matriz.GetLength(0); filas++)
{
for (int cols = 0; cols < matriz.GetLength(1); cols++)
{
Console.WriteLine($"Ingresa el valor [{filas}, {cols}]:");
matriz[filas, cols] = int.Parse(Console.ReadLine());
}
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: