Help on C# Static Class Exercise | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 1

Help on C# Static Class Exercise

The program you are given takes the N number as the size of an array, followed by N numbers. Complete the program to sort and output every element of an array, each on a new line. https://code.sololearn.com/cbH85DjjL9ox/?ref=app

19th May 2021, 1:52 PM
Robert L. Watkins III
Robert L. Watkins III - avatar
4 Réponses
+ 4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int count = Convert.ToInt32(Console.ReadLine()); int[] numbers = new int[count]; for (int i = 0; i < count; i++) { numbers[i] = Convert.ToInt32(Console.ReadLine()); } //your code goes here Array.Sort(numbers); for(int i=0; i<count; i++) { Console.WriteLine(numbers[i]); } } } }
30th Aug 2021, 8:07 AM
Khan Baz Khan Jadoon
Khan Baz Khan Jadoon - avatar
+ 2
+ After sorting the array, Array.Sort( numbers ); + Print each array element in distinct line, foreach( int value in numbers ) { Console.WriteLine( value ); }
19th May 2021, 2:06 PM
Ipang
0
I think this is the easiest solution and the best one for this task using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using static System.Console; namespace SoloLearn { class Program { static void Main(string[] args) { int count = Convert.ToInt32(Console.ReadLine()); int[] numbers = new int[count]; for (int i = 0; i < count; i++) { numbers[i] = Convert.ToInt32(Console.ReadLine()); } //your code goes here Array.Sort(numbers); for (int i = 0; i < count; i++) { WriteLine(numbers[i]); } } } }
20th Dec 2022, 11:31 PM
Muhammad Tariq Muhammad Muhammad Almanzalawy
Muhammad Tariq Muhammad Muhammad Almanzalawy - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int count = Convert.ToInt32(Console.ReadLine()); int[] numbers = new int[count]; for (int i = 0; i < count; i++) { numbers[i] = Convert.ToInt32(Console.ReadLine()); } //your code goes here Array.Sort(numbers); for (int i=0 ; i < count; i++) { Console.WriteLine(numbers[i]); } } } }
24th Mar 2024, 2:42 PM
Mahima Rathore
Mahima Rathore - avatar