Sunday, 1 December 2013

SORT AND REVERSE ARRAY PROGRAM--------

CODE:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SortandReverseArrayProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            //creating an array
            int[] x;
            x = new int[5];
            int n=x.Length;
            Console.WriteLine("Enter number");
            for (int i = 0; i < n; i++)
            {
                x[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Array before sorting");
            foreach (int i in x)
           
                Console.Write("  " + i);
            Console.WriteLine();
            //sorting and reversing the array elements
            Array.Sort(x); Array.Reverse(x);
            Console.WriteLine("Array after Sorting and Reversing");
            foreach (int i in x)
                Console.Write("  " + i);
            Console.WriteLine();
            Console.ReadKey();

         

        }
    }
}


OUTPUT:



No comments:

Post a Comment