[Solved] How to sort unknown number of numbers in C# with array or list?

  

3
Topic starter

Hi, please help me with this task:

Write a program that reads a number n and a sequence of n integers, sorts them and prints them.

Examples:

sort numbers c# example

sort numbers in c sharp examplle

1 Answer
2

Here is my solution with arrays and the Sort method of the Array Class:

using System;
 
class SortingNumbers
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] arrayNumbers = new int[n];
 
        for (int i = 0; i < n; i++)
        {
            arrayNumbers[i] = int.Parse(Console.ReadLine());
        }
 
        Array.Sort(arrayNumbers);
 
        foreach (var VARIABLE in arrayNumbers)
        {
            Console.WriteLine(VARIABLE);
        }
    }
}
Share: