Simple Swaping in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Swaping
{
classProgram
    {
staticvoid Main(string[] args)
        {
int[] a = newint [] { 4, 2, 5, 1, 3, 6 }; // user can put any value here and it will arrange it in ascending order.
int c = 0;
while (c != a.Length)
            {
for (int i = 0; i < a.Length – 1; i++)
                {
if (a[i] > a[i + 1])
                    {
int temp = a[i];
                        a[i] = a[i + 1];
                        a[i + 1] = temp;
                    }
                }
                c++;
            }
Console.WriteLine(“\n—————————————“);
for (int j = 0; j < a.Length; j++)
            {
Console.WriteLine(a[j]);
            }
Console.ReadLine();
        }
    }
}

Leave a comment