这是我正在做的练习:
编写一个创建一个包含5行和2行的二维数组的应用程序 4列。使用0到100之间的随机数填充数组。搜索 数组为最小值。显示最小的数组和索引 值存储。
这是我到目前为止的地方,可以使用一些帮助。目前我在粗线或用**括起来的线上得到两个错误(标识符预期)。我也不确定如果我朝着正确的方向前进。任何帮助或提示将不胜感激。我是一名商务专业的学生,以C#为选修课:(
Random random = new Random();
int smallest = 100;
int x = 0, y = 0;
int[,] numbers = {
{random.Next(1,100), random.Next(0,100), random.Next(0,100), random.Next(0,100)},
{random.Next(1,100), random.Next(0,100), random.Next(0,100), random.Next(0,100)},
{random.Next(1,100), random.Next(0,100), random.Next(0,100), random.Next(0,100)},
{random.Next(1,100), random.Next(0,100), random.Next(0,100), random.Next(0,100)},
{random.Next(1,100), random.Next(0,100), random.Next(0,100), random.Next(0,100)}
};
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
if (numbers[i, j] < smallest)
{
smallest = numbers[i, j];
x = i;
y = j;
}
**Console.WriteLine("Element({0},{1})={2}"... i, j, numbers[i, j]);**
}
Console.Write("\n\n smallest number is {0} at element [{1}, {2}]", smallest, x, y);
Console.ReadLine();
}
答案 0 :(得分:3)
试
Console.WriteLine("Element({0},{1})={2})", i, j, numbers[i, j]);