Sunday 20 April 2014

Ascending and descending order of array


Write a program in c# (c sharp) to accept 10 numbers in to array  form user and display it in Ascending and descending order.


using System;

namespace SortingOfArray
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] numarr = new int[10];

            Console.WriteLine("Enter  numbers :");
            for (int i = 0; i < 10; i++)
            {
                numarr[i] = Convert.ToInt32(Console.ReadLine());
            }

            Console.WriteLine("Ascending order of numbers :");
            Array.Sort(numarr);
            for(int i=0; i<10; i++)
            {
                Console.WriteLine(numarr[i]);
            }

            Console.WriteLine("Descending order of numbers :");
            Array.Sort(numarr);
            Array.Reverse(numarr);
            for(int i =0; i<10; i++)
            {
                Console.WriteLine(numarr[i]);
            }
            Console.ReadKey();
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com"

Thank you so much  :)

No comments:

Post a Comment