csharp 如何从控制台读取多维数组的示例。从计算机编程基础知识到C#http://www.introprogramm

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 如何从控制台读取多维数组的示例。从计算机编程基础知识到C#http://www.introprogramm相关的知识,希望对你有一定的参考价值。

Console.Write("Enter the number of the rows: ");
int rows = int.Parse(Console.ReadLine());

Console.Write("Enter the number of the columns: ");
int cols = int.Parse(Console.ReadLine());

int[,] matrix = new int[rows, cols];

Console.WriteLine("Enter the cells of the matrix:");

for (int row = 0; row < rows; row++)
{
  for (int col = 0; col < cols; col++)
  {
    Console.Write("matrix[{0},{1}] = ",row, col);
    matrix[row, col] = int.Parse(Console.ReadLine());
  }
}

for (int row = 0; row < matrix.GetLength(0); row++)
{
  for (int col = 0; col < matrix.GetLength(1); col++)
  {
    Console.Write(" " + matrix[row, col]);
  }
  Console.WriteLine();
}

//  Enter the number of the rows: 3
//  Enter the number of the columns: 2
//  Enter the cells of the matrix:
//  matrix[0,0] = 2
//  matrix[0,1] = 3
//  matrix[1,0] = 5
//  matrix[1,1] = 10
//  matrix[2,0] = 8
//  matrix[2,1] = 9
//  2 3
//  5 10
//  8 9

以上是关于csharp 如何从控制台读取多维数组的示例。从计算机编程基础知识到C#http://www.introprogramm的主要内容,如果未能解决你的问题,请参考以下文章

csharp 如何从控制台读取数组并打印它的示例。

csharp 如何从控制台读取数组并打印它的示例。

csharp 如何创建,初始化和打印多维数组(也称为矩阵)的示例。从计算机编程的基础知识

csharp 如何创建,初始化和打印多维数组(也称为矩阵)的示例。从计算机编程的基础知识

csharp 如何在多维数组中找到具有最高和的大小为2乘2的子矩阵的示例。从计算机程序基础

csharp 如何在多维数组中找到具有最高和的大小为2乘2的子矩阵的示例。从计算机程序基础