C# 输入数字

来源:百度知道 编辑:UC知道 时间:2024/05/28 01:53:48
int[] list ={ 1, 0, 6, 7, 5, 9, 2, 8, 4, 3 };
Console.Write("排序前:");
for (int i = 0; i < list.Length; i++)
Console.Write(list[i]);
Console.WriteLine();
int tmp = 0;
bool isOK = false;
while (!isOK)
{
isOK = true;
for (int i = 0; i < list.Length - 1; i++)
{
if (list[i] > list[i + 1])
{
tmp = list[i];
list[i] = list[i + 1];
list[i + 1] = tmp;
isOK = false;
}

}

}

Console.Write("排序后:");
for (int i = 0; i < list.Length; i++)
Console.Write(list[i]);

Console.ReadLine()
你想要实现数组排序不需要自己写代码,不然就是埋汰了C#的强大功能。如果是学习数据结构还说自己写,练练思维。下面我演示一下,用C#,从屏幕输入几个数,并保存在数组里面,实现排序和寻找最大值。
class Program
{
static void Main(string[] args)
{
int[] ArryIntBuff=new int[100];//缓存100个
bool Ent = false;//回车标志
bool Exit = false;//结束标志
string buff;//输入的字符串
int Index = 0;//记录输入了几个数
Console.WriteLine("输入数字,按回车输入,连按2次回车退出");
for (int i = 0; i < 100;i++ )
{
buff = Console.ReadLine();
if (buff.Length == 0)
{
if (Ent)
{
Exit = true;
}
else
{
Ent = true;
}
}
else