If you are a c# beginner or want to start learning the c# programming language, then this program will help you to understand the basics of c# programming. In this program, we are going to share C# program to describe the C# program to perform a selection sort.
To increase your C# knowledge, practice all C sharp programs:
Copy the below c# program and execute it in your Microsoft Visual Studio IDE (Integrated Development Environment ).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using System; class Program { static void Main(string[] args) { int array_size = 10; int[] array = new int[10] { 100, 50, 20, 40, 10, 60, 80, 70, 90, 30 }; Console.WriteLine("The Array Before Selection Sort is: "); for (int i = 0; i < array_size; i++) { Console.WriteLine(array[i]); } int tmp, min_key; for (int j = 0; j < array_size - 1; j++) { min_key = j; for (int k = j + 1; k < array_size; k++) { if (array[k] < array[min_key]) { min_key = k; } } tmp = array[min_key]; array[min_key] = array[j]; array[j] = tmp; } Console.WriteLine("The Array After Selection Sort is: "); for (int i = 0; i < 10; i++) { Console.WriteLine(array[i]); } Console.ReadLine(); } } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.