作业帮 > 数学 > 作业

C# 用random方法从1-100中随机产生n个随机数 然后把这n个随机数从这100个数中剔除出去

来源:学生作业帮 编辑:拍题作业网作业帮 分类:数学作业 时间:2024/04/27 22:47:56
C# 用random方法从1-100中随机产生n个随机数 然后把这n个随机数从这100个数中剔除出去
C# 用random方法从1-100中随机产生n个随机数 然后把这n个随机数从这100个数中剔除出去
这个应该没什么难度吧
再问: 我想要一下具体代码 你会的话 麻烦告诉一下
再答: 你的分太少了 能加分不
再问: 现在可以了吧
再答: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static List sjs;
static int[] cunchu;
static void Main(string[] args)
{
sjs = new List();

Console.WriteLine("请输入你要产生几位随机数:");
int j =Int16.Parse(Console.ReadLine());
for (int i = 0; i < j; i++)
{

int b = new Random().Next(100);
if (sjs.Contains(b))
{
i--;
}
else
{
sjs.Add(b);
}
}
for (int i = 1; i < 101; i++)
{
if (!sjs.Contains(i))
{
Console.WriteLine(i);
}
}
Console.ReadKey();
}
}
}