- 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
4 Respostas
+ 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]);
}
}
}
}
+ 2
+ After sorting the array,
Array.Sort( numbers );
+ Print each array element in distinct line,
foreach( int value in numbers )
{
Console.WriteLine( value );
}
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]);
}
}
}
}
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]);
}
}
}
}