Created
May 6, 2024 01:34
-
-
Save FleamRus/a2ea948f43ce07cbd707b000f1fe1e90 to your computer and use it in GitHub Desktop.
Сортировка чисел
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Сортировка_чисел | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Random random = new Random(); | |
int minRandom = 1; | |
int maxRandom = 10; | |
int[] numbers = new int[10]; | |
Console.WriteLine("Массив: \n"); | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
numbers[i] = random.Next(minRandom, maxRandom); | |
Console.Write(numbers[i] + " "); | |
} | |
Console.WriteLine("\nСортированные числа: "); | |
for (int i = 0; i < numbers.Length; i++) | |
for (int j = 0; j < numbers.Length - 1; j++) | |
if (numbers[j] > numbers[j + 1]) | |
{ | |
int t = numbers[j + 1]; | |
numbers[j + 1] = numbers[j]; | |
numbers[j] = t; | |
} | |
foreach (int number in numbers) | |
Console.WriteLine(number); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment