0% found this document useful (0 votes)
3 views

Array sort

This C# program sorts an array of integers in ascending order. It prompts the user to input the size of the array and its elements, then uses a nested loop to sort the elements. Finally, it displays the sorted array to the user.

Uploaded by

samadhan1157
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Array sort

This C# program sorts an array of integers in ascending order. It prompts the user to input the size of the array and its elements, then uses a nested loop to sort the elements. Finally, it displays the sorted array to the user.

Uploaded by

samadhan1157
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

public class Exercise11


{
public static void Main()
{
int[] arr1 = new int[10];
int n, i, j, tmp;

Console.Write("\n\nSort elements of array in ascending order :\n");


Console.Write("----------------------------------------------\n");

Console.Write("Input the size of array : ");


n = Convert.ToInt32(Console.ReadLine());

Console.Write("Input {0} elements in the array :\n",n);


for(i=0;i<n;i++)
{
Console.Write("element - {0} : ",i);
arr1[i] = Convert.ToInt32(Console.ReadLine());
}

for(i=0; i<n; i++)


{
for(j=i+1; j<n; j++)
{
if(arr1[j] < arr1[i])
{
tmp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = tmp;
}
}
}
Console.Write("\nElements of array in sorted ascending order:\n");
for(i=0; i<n; i++)
{
Console.Write("{0} ", arr1[i]);
}
Console.Write("\n\n");
}

You might also like