using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _5
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[100];
Random r = new Random();
int number;
for (int i = 0; i < 100; i++)
{
number= r.Next(1, 101);
for (int j = 0; j < array.Length; j++)
{
while(number==array[j])
}
}
array[i] = number;
}
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine("第{0}个数为{1}",i+1,array[i]);
}
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _5
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[100];
Random r = new Random();
int number;
for (int i = 0; i < 100; i++)
{
number= r.Next(1, 101);
for (int j = 0; j < array.Length; j++)
{
while(number==array[j])
{
number= r.Next(1, 101);//产生随机数,并且判断该值是否已经存在于数组中}
}
array[i] = number;
}
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine("第{0}个数为{1}",i+1,array[i]);
}
Console.ReadKey();
}
}
}