Last active
May 16, 2023 16:57
-
-
Save Strelok78/1fa77157cc4a189bf2d43319654a7d33 to your computer and use it in GitHub Desktop.
Outputs sorted numbers to the console, from the smallest to the largest. Array.Sort is not used.
This file contains hidden or 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.Runtime.CompilerServices; | |
namespace MyCode | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int arraySize = 10; | |
int maxValue = 20; | |
int[] ints = new int[arraySize]; | |
Random random = new Random(); | |
Console.WriteLine("Original array:"); | |
for (int i = 0; i < ints.Length; i++) | |
{ | |
ints[i] = random.Next(maxValue); | |
Console.Write(ints[i] + " "); | |
} | |
for (int i = 0; i < ints.Length; i++) | |
{ | |
for (int j = 0; j < ints.Length - 1; j++) | |
{ | |
if (ints[j] > ints[j + 1]) | |
{ | |
int temp = ints[j]; | |
ints[j] = ints[j + 1]; | |
ints[j + 1] = temp; | |
} | |
} | |
} | |
Console.WriteLine("\nSorted array:"); | |
foreach (int number in ints) | |
{ | |
Console.Write(number + " "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment