码迷,mamicode.com
首页 > 其他好文 > 详细

彩票 双色球 36选7

时间:2015-05-28 15:43:50      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

static void Main(string[] args)
        {
            for (int k = 0; k < 10; k++)
            {
                //输入
                Console.WriteLine("请输入要生成的彩票种类:1代表双色球,2代表36选7");
                int sr = Convert.ToInt32(Console.ReadLine());

                //判断输入的数
                if (sr == 1)
                {
                    shuangseqiu(); //双色球函数
                }
                else if (sr == 2)
                {
                    caipiao(); //36选7的函数
                }
            }
            
        }

        //双色球的函数
        public static void shuangseqiu()
        {
            //生成蓝球
            Random rd = new Random();
            int lan = rd.Next(1, 16);

            int[] hong = new int[6];
            //生成红球
            for (int i = 0; i < 6; i++)
            {
                int h = rd.Next(1, 33);

                bool cf = false;
                for (int j = 0; j < hong.Length; j++)
                {
                    if (hong[j] == h)
                    {
                        cf = true;
                        break;
                    }
                    else
                    {
                    }
                }

                if (cf == true)
                {
                    i--;
                }
                else
                {
                    hong[i] = h;
                }
            }

            Console.WriteLine("蓝球是:" + lan);
            Console.WriteLine("红球是:" + hong[0] + "," + hong[1] + "," + hong[2] + "," + hong[3] + "," + hong[4] + "," + hong[5]);
        }


        //生成36选7 的函数
        public static void caipiao()
        {
            Random rd = new Random();

            int[] qiu = new int[7];

            //生成球
            for (int i = 0; i < 7; i++)
            {
                int h = rd.Next(1, 36);
                
                bool cf = false;

                for (int j = 0; j < qiu.Length; j++)
                {
                    if (qiu[j] == h)
                    {
                        cf = true;
                        break;
                    }
                    else
                    {
                    }
                }

                if (cf == true)
                {
                    i--;
                }
                else
                {
                    qiu[i] = h;
                }
            }

            Console.WriteLine("生成的7个数为:" + qiu[0] + "," + qiu[1] + "," + qiu[2] + "," + qiu[3] + "," + qiu[4] + "," + qiu[5]+","+qiu[6]);

        }

 

彩票 双色球 36选7

标签:

原文地址:http://www.cnblogs.com/languang/p/4535821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!