3月13号 复习加函数

上午的主要内容是对于数数组的练习,主要是针对手机号码抽奖的问题,冒泡排序的问题做了整理的。以下会是案例的分析

 //输入n个手机号,抽奖活动,随机抽取一个5秒后停止

            Console.Write("请输入手机号码的个数");
            int n = int.Parse(Console.ReadLine());
            string[]shuzu=new string[n];//定义一个有n个手机号的数组
            for (int i=0;i<n ;i++ )
            {
                Console.Write(""+(i+1)+"个人的手机号码是:");
                shuzu[i]=Console.ReadLine();//接受数组
            }
            Console.WriteLine("所有号码输入完毕,按回车滚动");
            Console.ReadLine();
            Random ran = new Random();//初始化数组
            int m = 0;
            for (; ; )
            {
                int nn = ran.Next(n);//随机从n中截取
                Console.Clear();
                Console.WriteLine(shuzu[nn]);
                System.Threading.Thread.Sleep(100);//100毫秒,0.1秒           
                if (m == 49)//从0-49共50,50*0.1=5
                {
                   // Console.Clear();
                    //Console.Write(110);
                    break;
                }
                m++;
            }
            Console.ReadLine();

 

 int[] shuzu = new int[] { 3, 1, 8, 4, 0, 5, 6 };
            int zhong;
            for (int i = 0; i < 7; i++)
            {
                for (int j = i; j < 6; j++)
                {
                    if (shuzu[i] < shuzu[j + 1])
                    {
                        zhong = shuzu[i];
                        shuzu[i] = shuzu[j + 1];
                        shuzu[j + 1] = zhong;
                    }
                }
            }
            for (int i = 0; i < 7; i++)//排序之后打印
            {
                Console.WriteLine(shuzu[i]);
            }
            Console.ReadLine();

            //另一种打印的形式
            //foreach (int a in shuzu) 
            //{
            //    Console.WriteLine(a);
            //}
            //Console.ReadLine();

Console.Write("请输入班级的人数");
            int a = int.Parse(Console.ReadLine());
            double[]shuzu=new double[a];//成绩放到有a个人数的数组中
            if (a >= 5)
            {
                for (int i = 0; i < a; i++)
                {
                    Console.Write("" + (i + 1) + "个人的成绩是");
                    shuzu[i] = double.Parse(Console.ReadLine());//输入成绩的过程
                }
                //Console.WriteLine("每个人的成绩输入完毕,回车排序");
                //Console.ReadLine();
                double zhong;
                for (int i = 0; i < a; i++)//排序的过程
                {
                    for (int j = i; j < a - 1; j++)
                    {
                        if (shuzu[i] > shuzu[j + 1])
                        {
                            zhong = shuzu[i];
                            shuzu[i] = shuzu[j + 1];
                            shuzu[j + 1] = zhong;
                        }
                    }
                }
                //for (int i = 0; i < a; i++)
                //{
                //    Console.WriteLine(shuzu[i]);//排序后打印
                //}
                //Console.ReadLine();
                double he = 0;
                for (int i = 0; i < a; i++)
                {
                    he = he + shuzu[i];//索引都是从0开始的
                }

                double pj = (he - shuzu[0] - shuzu[1] - shuzu[a - 1] - shuzu[a - 2]) / (a - 4);
                Console.WriteLine("两个最低分是:" + (shuzu[0]) + "," + (shuzu[1]) + "");
                Console.WriteLine("两个最高分是:" + (shuzu[a - 2]) + "," + (shuzu[a - 1]) + "");
                Console.WriteLine("去掉两个最高和两个最低的平均分是:" + pj + "");           
            }
            else
            {
                Console.WriteLine("输入有误");
            }
            
            Console.ReadLine();

 

posted @ 2016-03-13 20:31  Durriya  阅读(197)  评论(0编辑  收藏  举报