【C#】比较N个数大小,从大到小排序,从小到大排序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
string tmp = "";
//顺序:从小到大
//string Txt = "从小到大排序:";
//for (int i = 0; i < iArray.Length; i++)
//{
// tmp += iArray[i] + " < ";
//}
//顺序:从大到小
string Txt = "从大到小排序:";
string[] Astr = str.Split(' ');
int[] iArray = new int[Astr.Length];
for (int j = 0; j < Astr.Length; j++)
{
iArray[j] = Convert.ToInt32(Astr[j]);
}
Array.Sort(iArray);
}
catch
{
Console.WriteLine("转换错误");
}
}
}
}
说明:以下内容是为了通过百度文库,所以将其重复。可以无视以下代码!
static void Main(string[] args)
{
try
{
Console.WriteLine("输入几个数字用空格隔开,按回车键结束:");
string str = Console.ReadLine().Trim();
}
catch
{
Console.WriteLine("转换错误");
}
}
}
static void Main(string[] args)
{
try
{
Console.WriteLine("输入几个数字用空格隔开,按回车键结束:");
string str = Console.ReadLine().Trim();
}
catch
{
Console.WriteLine("转换错误");
}
}
}
static void Main(string[] args)
{
try
{
Console.WriteLine("输入几个数字用空格隔开,按回车键结束:");
string str = Console.ReadLine().Trim();
string tmp = "";
//顺序:从小到大
//string Txt = "从小到大排序:";
//for (int i = 0; i < iArray.Length; i++)
//{
// tmp += iArray[i] + " < ";
//}
//顺序:从大到小
string Txt = "从大到小排序:";
string tmp = "";
//顺序:从小到大
//string Txt = "从小到大排序:";
//for (int i = 0; i < iArray.Length; i++)
//{
// tmp += iArray[i] + " < ";
//}
//顺序:从大到小
string Txt = "从大到小排序:";
}
catch
{
Console.WriteLine("转换错误");
}
}
}
for (int i = iArray.Length - 1; i >= 0; i--)
{
tmp += iArray[i] + " > ";
}
Console.WriteLine(Txt + tmp.Substring(0, tmp.Length - 3));//3——" < "的字符个数。
Console.ReadKey();
for (int i = iArray.Length - 1; i >= 0; i--)
{
tmp += iArray[i] + " > ";
}
Console.WriteLine(Txt + tmp.Substring(0, tmp.Length - 3));//3——" < "的字符个数。
Console.ReadKey();
for (int i = iArray.Length - 1; i >= 0; i--)
{
tmp += iArray[i] + " > ";
}
Console.WriteLine(Txt + tmp.Substring(0, tmp.Length - 3));//3——" < "的字符个数。
Console.ReadKey();
for (int i = iArray.Length - 1; i >= 0; i--)
{
tmp += iArray[i] + " > ";
}
Console.WriteLine(Txt + tmp.Substring(0, tmp.Length - 3));//3——" < "的字符个数。
Console.ReadKey();
string[] Astr = str.Split(' ');
int[] iArray = new int[Astr.Length];
for (int j = 0; j < Astr.Length; j++)
{
iArray[j] = Convert.ToInt32(Astr[j]);
}
Array.Sort(iArray);
string[] Astr = str.Split(' ');
int[] iArray = new int[Astr.Length];
for (int j = 0; j < Astr.Length; j++)
{
iArray[j] = Convert.ToInt32(Astr[j]);
}
Array.Sort(iArray);
string[] Astr = str.Split(' ');
int[] iArray = new int[Astr.Length];
for (int j = 0; j < Astr.Length; j++)
{
iArray[j] = Convert.ToInt32(Astr[j]);
}
Array.Sort(iArray);
string tmp = "";
//顺序:从小到大
//string Txt = "从小到大排序:";
//for (int i = 0; i < iArray.Length; i++)
//{
// tmp += iArray[i] + " < ";
//}
//顺序:从大到小
string Txt = "从大到小排序:";
}
catch
{
Console.WriteLine("转换错误");
}
}
}
static void Main(string[] args)
{
try
{
Console.WriteLine("输入几个数字用空格隔开,按回车键结束:");
string str = Console.ReadLine().Trim();
【比较N个数大小,从大到小排序,从小到大排序】
说明:以下代码通过C#控制台运行!
namespace N_order
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("输入几个数字用空格隔开,按回车键结束:");
string str = Console.ReadLine().Trim();
for (int i = iArray.Length - 1; i >= 0; i--)
{
tmp += iArray[i] + " > ";
}
Console.WriteLine(Txt + tmp.Substring(0, tmp.Length - 3));//3——" < "的字符个数。
Console.ReadKey();
}Βιβλιοθήκη Baidu
catch
{
Console.WriteLine("转换错误");
}
}
}
static void Main(string[] args)
{
try
{
Console.WriteLine("输入几个数字用空格隔开,按回车键结束:");
string str = Console.ReadLine().Trim();
for (int i = iArray.Length - 1; i >= 0; i--)
{
tmp += iArray[i] + " > ";
}
Console.WriteLine(Txt + tmp.Substring(0, tmp.Length - 3));//3——" < "的字符个数。
Console.ReadKey();
string[] Astr = str.Split(' ');
int[] iArray = new int[Astr.Length];
for (int j = 0; j < Astr.Length; j++)
{
iArray[j] = Convert.ToInt32(Astr[j]);
}
Array.Sort(iArray);
string tmp = "";
//顺序:从小到大
//string Txt = "从小到大排序:";
//for (int i = 0; i < iArray.Length; i++)
//{
// tmp += iArray[i] + " < ";
//}
//顺序:从大到小
string Txt = "从大到小排序:";
string tmp = "";
//顺序:从小到大
//string Txt = "从小到大排序:";
//for (int i = 0; i < iArray.Length; i++)
//{
// tmp += iArray[i] + " < ";
//}
//顺序:从大到小
string Txt = "从大到小排序:";
string[] Astr = str.Split(' ');
int[] iArray = new int[Astr.Length];
for (int j = 0; j < Astr.Length; j++)
{
iArray[j] = Convert.ToInt32(Astr[j]);
}
Array.Sort(iArray);
相关文档
最新文档