怎样随机数生成一数组,长度为10,随机数为1~100的奇数,求最大值最小值,C#语言

hansong316 1年前 已收到1个回答 举报

雪夜街灯ww 花朵

共回答了20个问题采纳率:90% 举报

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RandomArray
{
class Program
{
static void Main(string[] args)
{
int[] myRanArray = new int[10];
Random Ran = new Random();
for (int j = 0; j < 10; j++)
{
myRanArray[j] = 2 * Ran.Next(1,50) - 1;
}
Console.WriteLine("the Random Array is:");
int i=0;
int max = 0;
while (i < 10)
{
if (myRanArray[i] > max)
{
max = myRanArray[i];
}
Console.Write("{0} ",myRanArray[i]);
i++;
}
Console.WriteLine("nThe max number of the array is:{0}",max);
Console.ReadKey();
}
}
}
我是初学者,见笑了.

1年前

2
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.021 s. - webmaster@yulucn.com