您的位置:首页 > 编程语言 > C#

C#--设计一个程序,输入10个数存入数组中,然后实现冒泡排序

2012-10-26 20:36 1166 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {//4.设计一个程序,输入10个数存入数组中,然后实现冒泡排序。

        static void Main(string[] args)
        {

            int[] nums = { 2, 5, 1, 7, 9, 5, 4, 3, 7, 8 };

            for (int i = 0; i < nums.Length; i++)
            {
                for (int j = i + 1; j < nums.Length; j++)
                {
                    if (nums[i] > nums[j])
                    {
                        int t;

                        t = nums[i];

                        nums[i] = nums[j];

                        nums[j] = t;

                       
                    }
                 
                }
                Console.Write(nums[i]);
            }
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐