美文网首页
编写程序,定义一个6*8的二维数组,随机产生48个10到99之间

编写程序,定义一个6*8的二维数组,随机产生48个10到99之间

作者: 唯一的one | 来源:发表于2018-11-29 20:29 被阅读0次
image.png
image.png
 Random random = new Random();
            int max = 0;
            int min = int.MaxValue;
            int index1 = 0;
            int index2 = 0;
            int index3 = 0;
            int index4 = 0;
            int[,] a = new int[6, 8];
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    a[i, j] = random.Next(10, 100);
                    if (a[i, j] > max)
                    {
                        max = a[i, j];
                        index1 = i;
                        index2 = j;
                    }
                    if (a[i, j] < min)
                    {
                        min = a[i, j];
                        index3 = i;
                        index4 = j;
                    }
                    Console.Write(a[i, j] + "\t");
                }
                Console.WriteLine();
            }
            Console.WriteLine("最大值是{0},下标是{1},{2}", max, index1, index2);
            Console.WriteLine("最小值是{0},下标是{1},{2}", min, index3, index4);

相关文章

网友评论

      本文标题:编写程序,定义一个6*8的二维数组,随机产生48个10到99之间

      本文链接:https://www.haomeiwen.com/subject/xbkqcqtx.html