User input into a two dimensional array

前端 未结 6 1760
生来不讨喜
生来不讨喜 2021-01-07 13:44

I\'m completely new to C# and well I would like simple code to create a matrix from user input

E.G.

int [,] matrix1 = new int [2,2]
// now using inpu         


        
6条回答
  •  囚心锁ツ
    2021-01-07 14:32

    static void Main(string[] args)
    {
       int[,] matrix1 = new int[2, 2];
    
       for (int i = 0; i < 2; i++)
       {
             for (int j = 0; j < 2; j++)
             {
                matrix1[i, j] = Int32.Parse(Console.ReadLine());  
             }
       }
    
       for (int i = 0; i < 2; i++)
       {
              for (int j = 0; j < 2; j++)
              {
                 Console.WriteLine("Element({0},{1})={2}", i, j, matrix1[i, j]);
              }
       }
    }
    

提交回复
热议问题