第十一次作业第二题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{

static void Main(string[] args)
{
try
{
Console.WriteLine("请输入6个数字");
int[] num = new int[6];
int temp = 0;
for (int i = 0; i < num.Length; i++)
{
Console.Write("第{0}个数字:", i+1);
num[i] = Convert.ToInt32(Console.ReadLine());

            for (int j = 0; j < num.Length - 1; j++)            
            {if(num[j]>num[j+1])
                 temp = num[j];
                num[j] = num[j + 1];
                num[j + 1] = temp;
            }

        }
        Array.Sort(num);
        for(int i =0; i<num.Length;i++)
        {
            Console.Write("{0},", num[i]);
        }
        


    }
    catch
    {
        Console.WriteLine("输入错误");
    }


    Console.ReadKey();
}

}

}

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容