We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, June 19, 2015

Bubble Sort program In Array


    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the size of array");
            int n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];
            Console.WriteLine("Enter the array elements");
            for (int i = 0; i < n; i++)
            {
                arr[i] = int.Parse(Console.ReadLine());
            }
                      
            for (int j = 0; j <= arr.Length - 2; j++)
            {
                for (int i = 0; i <= arr.Length - 2; i++)
                {
                    if (arr[i] > arr[i + 1])
                    {
                        n = arr[i + 1];
                        arr[i + 1] = arr[i];
                        arr[i] = n;
                    }
                }
            }

            Console.WriteLine("This Array is sorted");
            foreach (int result in arr)
            {
                Console.Write(result + " ");
            }
            Console.ReadLine();

        }

    }

OUTPUT:

No comments: