7个数进行冒泡排序之后输出

来源:互联网 发布:亚马逊kindle windows 编辑:程序博客网 时间:2024/06/05 20:22
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication3{    class Program    {        static void Main(string[] args)        {            int[] shu=new int[7];            int bian=0;            Console.WriteLine("请输入7个数");            for (int i = 0; i < shu.Length;i++ )            {                Console.WriteLine("请输入第{0}个数",i+1);                shu[i]=int.Parse(Console.ReadLine());            }                       for (int i = 0; i < shu.Length - 1;i++ )            {                for (int j = 0; j < shu.Length - 1 - i;j++ )                {                    if(shu[j]>shu[j+1])                    {                        bian = shu[j];                        shu[j] = shu[j + 1];                        shu[j + 1] = bian;                    }                }            }            Console.WriteLine("7个数冒泡排序之后输出");            for (int i = 0; i < shu.Length;i++ )            {                Console.Write(shu[i]+" ");            }            Console.ReadLine();        }    }}

0 0
原创粉丝点击