forked from kiba518/CSharpClassicProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
何意数排序.txt
49 lines (48 loc) · 1.17 KB
/
何意数排序.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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<array_previous.Length;i++)
{
Console.WriteLine ("请输入第{0}个数:",i+1);
array_previous[i]=int.Parse (Console.ReadLine ());
}
for(int index=1;index<array_previous.Length;index++)
{
if(array_previous[index-1]<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 ();
for(int index=1;index<array_previous.Length;index++)
{
if(array_previous[index-1]>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 ();
}
}