C# 第二章 长度为7的数组的冒泡排序

来源:互联网 发布:dnf面板数据怎么看 编辑:程序博客网 时间:2024/06/11 16:56
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication2{    class Program    {                static void Main(string[] args)        {            int[] array = new int[7];            int i, j;            int sll;            for (i = 0; i < array.Length; i++) {                Console.WriteLine("输入第{0}个成绩:",i+1);                array[i] = int.Parse(Console.ReadLine());            }            Console.WriteLine("排序前成绩:");            for (i = 0; i < array.Length; i++)            {                Console.Write("{0}\t", array[i]);            }            for (i = 0; i < array.Length - 1; i++)            {                for (j = 0; j < array.Length - 1 - i; j++)                {                    if (array[j] > array[j + 1])                    {                        sll = array[j];                        array[j] = array[j + 1];                        array[j + 1] = sll;                    }                }            }            Console.WriteLine("排序后成绩:" );            for (i = 0; i < array.Length;i++ )            {                Console.Write("{0}\t", array[i]);                           } Console.ReadLine();        }    }}

0 0
原创粉丝点击