指定数字排序

 lab :
            Console.WriteLine("比较5个数字的大小");
            Console.WriteLine("请输入第一个数字:");
            int n1 =Convert.ToInt32( Console.ReadLine());
            Console.WriteLine("请输入第二个数字:");
            int n2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入第三个数字:");
            int n3 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入第四个数字:");
            int n4 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入第五个数字:");
            int n5 = Convert.ToInt32(Console.ReadLine());
            int[] a = new int[5] { n1,n2,n3,n4,n5};
            int temp;
           
            //外循环           
            for (int outer = 4; outer >= 1; outer--)
            {
                for (int inner = 0; inner <= outer - 1; inner++)
                {
                    if (a[inner] > a[inner + 1])
                    {
                        temp=a[inner];
                        a[inner]=a[inner+1];
                        a[inner + 1] = temp;
                    }
                }
            }
            Console.WriteLine("排序后的结果是:");
            for (int i = 0; i <= 4; i++)
            {
                Console.WriteLine(a[i]+"  ");
            }
            Console.WriteLine("如果继续执行请输入Y,否则请输入任意键");
            if (Console.ReadLine().ToLower() == "Y")
            { }
          
                goto lab;
          

本文出自 “BtarBrightDream” 博客,谢绝转载!

你可能感兴趣的:(职场,C#,休闲)