10个随机数排序(冒泡排序)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

namespace _1到100内随机十个数排序

{

    class Program

    {

        static void Main(string[] args)

        {

            CreatRandArray();

            Console.WriteLine(" ");

            CreatSortArray();

            Console.Write("递增数列:" + " ");

            foreach (int item in Array)

            {

                if (item / 10 < 1)

                { Console.Write('0' + item.ToString() + " "); }

                else

                { Console.Write(item + " "); }

            }

            Console.ReadKey();

        }

        static int num;

        static int max;

        static int[] Array = new int[10];

        private static void CreatRandArray()

        {

            Random rd = new Random();

            for (int i = 0; i <= 9; i++)

            {

                num = rd.Next(1, 100);

                Array[i] = num;

            }

            Console.Write("随机数列:" + " ");

            foreach (int item in Array)

            {

                if (item / 10 < 1)

                { Console.Write('0' + item.ToString() + " "); }

                else

                { Console.Write(item + " "); }

            }


        }

        private static void CreatSortArray()

        {

            int temp;

            for (int i = 0; i < Array.Length - 1; i++)

            {

                for (int j = i + 1; j < Array.Length; j++)

                {

                    if (Array[i] > Array[j])

                    {

                        temp = Array[j];

                        Array[j] = Array[i];

                        Array[i] = temp;

                    }

                }

            }

        }

    }

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 14,356评论 0 33
  • Java经典问题算法大全 /*【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子...
    赵宇_阿特奇阅读 5,955评论 0 2
  • using System; using System.Collections.Generic; using Sys...
    小兔哈尼阅读 5,573评论 0 0
  • 拥抱结束, 计程车缓缓停下。 一只拉杆箱,背影清癯。 我没有倾城之貌, 没有漆黑发亮的大眼睛, 更没有绳索和脚镣。...
    司徒镜心阅读 2,895评论 0 0
  • 宜舒家(国内功能型湿巾行业创新品牌) 宜舒家,是浙江省纺织品进出口集团有限公司旗下品牌,专注湿巾领域。主要产品类别...
    zqfyzj阅读 2,755评论 0 0

友情链接更多精彩内容