美文网首页
随机产生5个1-100的数,求其中的最大值。

随机产生5个1-100的数,求其中的最大值。

作者: 唯一的one | 来源:发表于2018-11-29 20:22 被阅读0次
image.png
image.png
 Random random = new Random();
            int[] a = new int[5];
            int max = 0;
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = random.Next(1, 100);
                Console.WriteLine(a[i]);
                if (max < a[i])
                {
                    max = a[i];
                }
            }
            Console.WriteLine("最大值是" + max);

相关文章

网友评论

      本文标题:随机产生5个1-100的数,求其中的最大值。

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