-1

这是我正在做的练习:

编写一个应用程序,创建一个 5 行 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(); 
}
4

1 回答 1

3

尝试

Console.WriteLine("Element({0},{1})={2})", i, j, numbers[i, j]);
于 2013-04-01T03:40:27.323 回答