Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sorting an array means to arrange its elements in increasing order.
- // Write a program to sort an array. Use the "selection sort" algorithm:
- // Find the smallest element, move it at the first position, find the
- // smallest from the rest, move it at the second position, etc.
- using System;
- class SortArray
- {
- static void Main()
- {
- int[] array = new int[10];
- int minValue;
- int changer;
- for (int index = 0; index < 10; index++)
- {
- array[index] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < 9; i++)
- {
- minValue = i;
- for (int k = i + 1; k < 10; k++)
- {
- if (array[minValue] > array[k])
- {
- minValue = k;
- }
- }
- changer = array[minValue];
- array[minValue] = array[i];
- array[i] = changer;
- }
- for (int i = 0; i < 10; i++)
- {
- Console.WriteLine(array[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement