注:这些排序的数据都是要自己插入的,不能人为定值?

解决方案 »

  1.   

    c# 的好处就是比C语言多了许多系统自带的常用功能,其中包括排序 
    int []num=new int[lenght];
    int []sort_num=num.sort(); //记得是这个,我自己从来没用过这方法。
    foreach(int i in sort_num)
    {
        console.write(i+"  ");
    }
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;namespace tt
    {
        class Program
        {
            static void Main(string[] args)
            {
                ArrayList ar = new ArrayList();
                int a;
                while (true)
                {
                    a = Convert.ToInt32(Console.Read());
                    ar.Add((int)a);
                    ar.Sort();
                }
            }
        }
    }如果还要将ArrayList转换为一维数组,可以用ToArray()
      

  3.   

    应该是Console.ReadLine() 打错了
      

  4.   

    这和C,C#编译有什么关系
    用C的话,还要用冒泡或者其他排序法进行排列
    C#中提供了ArrayList结构,可以方便地进行数组的相关操作,同时还支持ArrayList到一维数组之间的转换
      

  5.   

    // 1111.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"int main(int argc, char* argv[])
    {
    int array[10];
    int i,j,temp;
    for( i=0;i<10;i++)
        scanf("%d",&array[i]);
    for(i=0;i<10;i++)
    printf("%d,",array[i]);
    printf("\n");
    for(i=10;i>0;i--)
    for(j=0;j<i-1;j++)
    if(array[j]<array[j+1])
    {
    temp=array[j+1];
    array[j+1]=array[j];
    array[j]=temp;
    }
    for(i=0;i<10;i++)
    printf("%d,",array[i]); return 0;
    }
    上面是c的排序代码,那么c#怎么打呢?
      

  6.   

    int[] array=new int[10]; 
    int i,j,temp; 
    for( i=0;i <10;i++) 
        array[i]=Convert.ToInt32(Console.ReadLine());
    for(i=0;i <10;i++) 
    Console.WriteLine(array[i].ToString());
    for(i=10;i>0;i--) 
    for(j=0;j <i-1;j++) 
    if(array[j] <array[j+1]) 

    temp=array[j+1]; 
    array[j+1]=array[j]; 
    array[j]=temp; 

    for(i=0;i <10;i++) 
    Console.WriteLine(array[i].ToSting());应该差不多了
      

  7.   

    谢谢,帮大忙了,不过也有小小错误,最后一句
    Console.WriteLine(array[i].ToSting()); 
    应改为:Console.WriteLine(array[i]);就行了
    修改后代码:
    using System;
    using System.Collections.Generic;
    using System.Text;namespace test2
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] array = new int[10];
                int i, j, temp;
                for (i = 0; i < 10; i++)
                
                    array[i] = Convert.ToInt32(Console.ReadLine());
                    Console.Clear();
                
                for (i = 0; i < 10; i++)
                    Console.Write(array[i].ToString()+",");
                Console.WriteLine("\r");
                for (i = 10; i > 0; i--)
                    for (j = 0; j < i - 1; j++)
                        if (array[j] < array[j + 1])
                        {
                            temp = array[j + 1];
                            array[j + 1] = array[j];
                            array[j] = temp;
                        }
                for (i = 0; i < 10; i++)
                    Console.Write(array[i]+",");
                Console.ReadKey();
            }
            
        }
    }