【发布时间】:2016-11-28 12:05:58
【问题描述】:
控制台提示用户输入他的数组,我能够在用户输入他的输入之前放置一个 0 的列,我需要在用户完成后在数组的末尾放置一个 0 的列.
谢谢
【问题讨论】:
-
对于那些过于宽泛的人......这是他使用的完整代码stackoverflow.com/a/40761005/2592042
-
感谢您提及。
控制台提示用户输入他的数组,我能够在用户输入他的输入之前放置一个 0 的列,我需要在用户完成后在数组的末尾放置一个 0 的列.
谢谢
【问题讨论】:
我确定您正在使用此代码在矩阵之前插入 0。 How to add a column to the an array C#
此代码所需的更改是
//c++; //remove this line
c = c + 2; //add two extra column for adding 0's, One for beginning one for end
int[,] matrix = new int[r, c];
其他变化是
for (int row = 0; row < r; row++)
{
for (int col = 0; col < c - 1; col++) // reduce column loop by one
{
if (col == 0)
{
matrix[row, col] = 0;
}
else
{
Console.Write("Enter value for matrix[{0},{1}] = ", row, col - 1);
matrix[row, col] = (int)Convert.ToInt32(Console.ReadLine());
}
}
}
【讨论】:
for (int row = 0; row < r; row++)
{
for (int col = 0; col < c-1; col++)
{
Console.Write("Enter value for matrix[{0},{1}] = ", row, col - 1);
matrix[row, col] = (int)Convert.ToInt32(Console.ReadLine());
}
matrix[row, col] = 0;
}
【讨论】: