Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Random random = new Random();
- int arrayLength = 30;
- int minimumNumberInArray = 1;
- int maximumNumberInArray = 9;
- int[] array = new int[arrayLength];
- bool needSortArray = true;
- Console.WriteLine($"Одномерный массив с длиной {arrayLength}:");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(minimumNumberInArray, maximumNumberInArray + 1);
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- while (needSortArray)
- {
- needSortArray = false;
- for (int i = 1; i < array.Length; i++)
- {
- if(array[i] < array[i - 1])
- {
- int tempNumber = array[i];
- array[i] = array[i - 1];
- array[i - 1] = tempNumber;
- needSortArray = true;
- }
- }
- }
- Console.WriteLine($"Отсортированный массив:");
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement