| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 882 人关注过本帖
标题:多个数排序的代码
只看楼主 加入收藏
风霜
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:7
帖 子:242
专家分:0
注 册:2005-3-4
收藏
 问题点数:0 回复次数:4 
多个数排序的代码

using System;

namespace n个数排序 { class Class1 { static void Main(string[] args) {Console.WriteLine("请输入你要排几个数的顺序:\n"); int n;//接收你要几个数排序 n=int.Parse(Console.ReadLine()); int[] A=new int[n]; Console.WriteLine("请依次输入你要排序的数(数的结束用回车表示):\n"); for(int i=0;i<n;i++)//接收你要排序的数 A[i]=int.Parse(Console.ReadLine()); for(int i=0;i<n;i++)//排序 { for(int j=i+1;j<n;j++) { int temp; if(A[i]>A[j]) { temp=A[j]; A[j]=A[i]; A[i]=temp; } } } Console.WriteLine("排序的结果为:\n"); for(int i=0;i<n;i++) Console.Write(" "+A[i]);

System.Threading.Thread.Sleep(10000); } } }

搜索更多相关主题的帖子: 代码 
2005-04-04 18:02
jacky
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2004-12-17
收藏
得分:0 
using System;
public class Test
{
 public static void Main()
 {
   
  int x;
  int temp;
  Console.WriteLine ("你想排几个数的序:");
  x=int.Parse (Console.ReadLine ());
  int[] array_previous=new int [x];
  for(int i=0;i&lt;array_previous.Length;i++)
  {
   Console.WriteLine ("请输入第{0}个数:",i+1);
   array_previous[i]=int.Parse (Console.ReadLine ());
  }
  for(int index=1;index&lt;array_previous.Length;index++)
  {
   
   if(array_previous[index-1]&lt;array_previous[index])
   {
    temp=array_previous[index-1];
    array_previous[index-1]=array_previous[index];
    array_previous[index]=temp;
   }
  }
  Console.WriteLine ("正序排列为:");
  foreach(int pin in array_previous)
  {
   Console.Write (pin+"\t");
  }
  Console.WriteLine ();
 }
}
2005-04-04 18:29
yichen
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2005-3-9
收藏
得分:0 
多个数排序,也可以这样写。
我这里可以正着排序,也可以逆着排序。


using System;

class My
{
static void Main()
{
Console.WriteLine("请输入你想排序的数字的个数:");
int a=int.Parse(Console.ReadLine());
int[] b=new int[a];
int[] e=new int[a];
int f=-1;
for(int i=0;i&lt;a;i++)
{
int c=i+1;
Console.WriteLine("请输入第"+c+"个数");
int d=int.Parse(Console.ReadLine());
b[i]=d;
}
Console.WriteLine("排序前的顺序是:");
for(int i=0;i&lt;a;i++)
{
Console.Write(b[i]+"\t");
}
Console.WriteLine("\n");
Array.Sort (b);
Console.WriteLine("从小到大的顺序是");
for(int i=0;i&lt;a;i++)
{
Console.Write(b[i]+"\t");
}
Console.WriteLine("\n");
Console.WriteLine("从大到小的顺序是");
for(int j=a-1;j&gt;=0;j--)
{
f++;
e[f]=b[j];
Console.Write(e[f]+"\t");
}
System.Threading.Thread.Sleep(10000);
}
}


衣带渐宽终不悔, 为伊消得人憔悴。 纸上得来终觉浅, 绝知此事要躬行。
2005-04-04 18:31
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
二楼写的好像不行啊。
三楼写得不错。

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-05 08:58
nyzfl
Rank: 1
等 级:新手上路
帖 子:278
专家分:0
注 册:2005-3-21
收藏
得分:0 
支持一下

My-Blog地址:http://fenglin.
2005-04-05 12:04
快速回复:多个数排序的代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016779 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved