c# 使用“冒泡”法对数组元素进行排序

c# 使用“冒泡”法对数组元素进行排序,第1张

概述结果如图所示代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp3__冒泡_法排序_数组_{    class Program    {        static void Ma...

结果如图所示

代码如下:

using System;
using System.Collections.Generic;
using System.linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApp3__冒泡_法排序_数组_
{
    class Program
    {
        static voID Main(string[] args)
        {
            double[] a = new double[10];
            Console.Writeline("请输入10个数:");
            for(int i = 0; i < 10; i++)
            {
                Console.Write("第{0}个数:",i+1);
                a[i] = double.Parse(Console.Readline());
            }
            for(int i = 0; i < 10; i++)
            {
                Console.Write("{0}\t",a[i]);
            }
            Console.Writeline();
            double temp;
            for(int i = 0; i < 9; i++)
            {
                for(int j = 0; j < 9-i ; j++)
                {
                    if (a[j] > a[j+1])
                    {
                        temp = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = temp;
                    }
                }
            }
            Console.Writeline("排好序为:");
            for(int j = 0; j < 10; j++)
            {
                Console.Write("{0}\t",a[j]);
            }
        }
    }
}

总结

以上是内存溢出为你收集整理的c# 使用“冒泡”法对数组元素进行排序全部内容,希望文章能够帮你解决c# 使用“冒泡”法对数组元素进行排序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/1212887.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存