Hello, I’m working on this task:
Call a method GetNumbersFromConsole that reads a count value of int, and then reads count values from the console into an int array. Print all values from the array on one line, in reverse order, each separated by a space. For the purposes of this task, you should NOT have a space at the end of the line. For example:
>3
>1
>2
>3
3 2 1
/*NOTE: Do not use Console.Write(“\b”) to delete the last character. It is not supported by the code runner.*/
Here is my code:
using System;
namespace Arrays
{
class ReverseArray
{
public static void Main(string[] args)
{
int[] myArray = GetNumbersFromConsole();
for (int i = myArray.Length - 1;i >= 0; – i)
/* 3=3-1; 3>0;
2=2-1; 2>0;
1=1-1; 1>0;*/
{
Console.Write(" ");
Console.Write(myArray[i]);
}
// Write your code here
}
static int[] GetNumbersFromConsole()
{
int count = int.Parse(Console.ReadLine()); //3
int[] result = new int[count]; //genetared array only cells 0 1 2
for(int i = 0; i < count; ++i)
{
result[i] = int.Parse(Console.ReadLine()); // repeating array to input numbers
}
return result; //my array (numbers) 5 6 7
}
}
}
Can anyone please help me to solve it?