c#随机产生1~20之间的整数,总共生成1000次,统计其中生成的整数0,1,2,3,...…,20的个数分别是多少

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 19:04:10
c#随机产生1~20之间的整数,总共生成1000次,统计其中生成的整数0,1,2,3,...…,20的个数分别是多少
xŒJ@_eH4;ݸtd16im'e&(*U(E(Bo#DI%E7Ʉs>ar:7٬{A㟶]M>z~skFz{oI{*ݵxh}B NAYgr#r;M=WijT9}g^5ޯR1LER~66"DbŤ56Kf1Y@- Cd";݌HBXʌ8t/s,6DJ%kۑj`bE'Šl48eE [4WǜM]kKJTtE& # 1cKD@B漵#LW+#

c#随机产生1~20之间的整数,总共生成1000次,统计其中生成的整数0,1,2,3,...…,20的个数分别是多少
c#随机产生1~20之间的整数,总共生成1000次,统计其中生成的整数0,1,2,3,...…,20的个数分别是多少

c#随机产生1~20之间的整数,总共生成1000次,统计其中生成的整数0,1,2,3,...…,20的个数分别是多少
控制台程序
class Program
{
static void Main(string[] args)
{
Random ran = new Random();
int[] nums = new int[1000];
for (int i = 0; i < 1000; i++)
{
nums[i] = ran.Next(1,21);
}
int[] result = new int[21];
for (int i = 0; i < 1000; i++)
{
result[nums[i]]++;
}
for (int i = 1; i < 21; i++)
{
Console.WriteLine("{0}:{1}",i,result[i]);
}
Console.WriteLine("dkjfas");
Console.ReadKey();
}
}