The first line will contain a message prompt to input the number of elements.
The second line will contain message prompts for the elements of the array.
The succeeding lines will contain the arranged elements of the array. Make sure to print the numbers in the order in which they appear in the input. In this case, since 6 appeared first before 12, 6 is printed first.
public static void Main()
{
Console.WriteLine("Please enter array length");
var arrayLength = Convert.ToInt32(Console.ReadLine());
var array = InitArray(arrayLength);
PrintArray(array);
Console.ReadLine();
}
public static void PrintArray(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
if (i == arr.Length - 1)
{
Console.Write(arr[i]);
}
else
{
Console.Write("{0},",arr[i]);
}
}
Console.WriteLine();
}
private static int[] InitArray(int arraySize) {
var array = new int[arraySize];
for (int i = 0; i < arraySize; i++)
{
Console.WriteLine("Please enter {0} array element", i);
array[i] = Convert.ToInt32(Console.ReadLine());
}
return array;
}
Comments
Leave a comment