using System;
namespace csharpconsole
{
class Program
{
static void Main(string[] args)
{
int total = 36000;
int[] count = new int[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Random r = new Random((int)DateTime.Now.Ticks);
for (int i = 0; i < total; i++)
{
int x1 = r.Next(1,7);
int x2 = r.Next(1, 7);
int sum = x1 + x2;
count[sum - 2]++;
}
Console.WriteLine("点数和\t出现比率");
for (int i = 0; i < 11; i++)
{
double rate = ((double)count[i]) / ((double)total);
rate *= 100;
Console.WriteLine(string.Format("{0}\t{1}%", i+2, rate.ToString(".00")));
}
Console.ReadKey();
}
}
}
温馨提示:答案为网友推荐,仅供参考