Objective
Write a C# program to ask the user for 10 integer numbers (from -1000 to 1000), sort them and display them sorted.
Write Your C# Exercise
C# Exercise Example
using System; // Importing the System namespace to access basic classes like Console
class Program
{
static void Main()
{
int[] numbers = new int[10]; // Declare an array to store 10 integer numbers
// Ask the user for 10 integer numbers within the range of -1000 to 1000
for (int i = 0; i < numbers.Length; i++)
{
Console.Write($"Enter number {i + 1} (from -1000 to 1000): ");
numbers[i] = int.Parse(Console.ReadLine()); // Store each entered number in the array
}
// Sort the array of numbers in ascending order
Array.Sort(numbers); // Use the Array.Sort method to sort the numbers
// Display the sorted numbers
Console.WriteLine("\nSorted numbers:");
foreach (int number in numbers)
{
Console.WriteLine(number); // Print each number in the sorted array
}
}
}