1
Reply

How to Sort elements in Ascending Order of the array.

Purushottam Rathore

Purushottam Rathore

Apr 08, 2011
5k
0

    static void Main(string[] args)
            {
                int[] num = new int[] { 20, 50, 10, 70, 40, 80, 30, 90, 60 };
                int t = 0;
                for (int i = 0; i < num.Length; i++)
                {
                    for (int j = i + 1; j < num.Length; j++)
                        if (num[i] > num[j])
                        {
                            t = num[i];
                            num[i] = num[j];
                            num[j] = t;
                        }
                }
                Console.WriteLine("Sorting elements in Ascending Order :\n");
                for (int i = 0; i < num.Length; i++)
                    Console.WriteLine(num[i]);
                Console.ReadLine();
            }

    Purushottam Rathore
    April 08, 2011
    0