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:
Post a Comment