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
网友评论