I want to reverse an array with console.ReadLine()
, but I'm stuck.
Here is statement of problem.
Give an array of 10 natural numbers. Displays the numbers in the string in reverse order.
The numbers in the string are given on a single line and are separated by a space. The application will display the numbers on a single line, separated by a space between them.
Example:
For input data:
1 2 3 4 5 6 7 8 9 10
The console will display:
10 9 8 7 6 5 4 3 2 1
here is my code:
string number = Convert.ToString(Console.ReadLine());
List<string> originalList = new List<string>();
for (int i = 0; i < 1; i++)
{
originalList.Add(number);
}
foreach (string item in originalList)
{
Console.Write(item + " ");
}
originalList.Reverse();
foreach (string item in originalList)
{
Console.WriteLine(item + " ");
}
Console.WriteLine();