C# 第二章冒泡排序

来源:互联网 发布:淘宝试用中心 编辑:程序博客网 时间:2024/06/08 14:55
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication6{    class Program    {        static void Main(string[] args)        {            int[] score = new int[5];            int i, j;            int temp;            Console.WriteLine("请输入5个学员的成绩");            for(i=0;i<score.Length;i++){                Console.WriteLine("请输入第{0}个学员的成绩:",i+1);            score[i] =int .Parse(Console.ReadLine());        }            for (i = 0; i < score.Length - 1; i++)            {                for (j = 0; j < score.Length - 1 - i; j++)                {                    if (score[j] > score[j + 1])                    {                        temp = score[j];                        score[j] = score[j + 1];                        score[j + 1] = temp;                    }                }            } Console.WriteLine("排序后:");            for (i = 0; i < score.Length; i++)            {                Console.Write("{0}\t", score[i]);            } Console.ReadLine();        }    }}

0 0
原创粉丝点击