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

问题描述:

怎样随机数生成一数组,长度为10,随机数为1~100的奇数,求最大值最小值,C#语言
1个回答 分类:综合 2014-12-15

问题解答:

我来补答
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();
}
}
}
我是初学者,见笑了.
 
 
展开全文阅读
剩余:2000