Sorting Program using C#
In this program, just sort the numbers without using any methods.....
To open the Console application and write the code
namespace SortingNos
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Numbers :");
int[] arr = new int[5];
string arr1 = "";
for (int i = 0; i < 5; i++)
{
arr1 = Console.ReadLine();
arr[i] = Convert.ToInt32(arr1);
}
int a, b, temp = 0;
Console.WriteLine();
for (a = 0; a < arr.Length; a++)
{
for(b=a+1;b< arr.Length;b++)
{
if (arr[a] > arr[b])
{
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
}
Console.WriteLine(arr[a]);
}
Console.ReadLine();
}
}
}
run the program....The sample output is
Enter Numbers :
50
23
10
4
7
Below are The sorted numbers
4
7
10
23
50
Naga116, if this helps please login to Mark As Answer. | Alert Moderator