-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayReverse.cs
50 lines (40 loc) · 1.44 KB
/
ArrayReverse.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
namespace ReversedArray
{
class Program
{
static void Main(string[] args)
{
// Declare and initialize an array
int[] myArray = { 23, 45, 67, 12 };
// Create a reversed array
int[] revArray = new int[myArray.Length];
// Initialize the reversed array
for(int index = 0; index < myArray.Length; index++)
{
revArray[myArray.Length - index - 1] = myArray[index];
}
// Print the reversed array
for(int index = 0; index < myArray.Length; index++)
{
Console.Write(revArray[index] + " ");
}
// Reading array from the console
Console.WriteLine("-------------------------");
Console.Write("Enter an integer: ");
int n = int.Parse(Console.ReadLine());
int[] array = new int[n];
Console.WriteLine("Enter the array: ");
for (int i = 0; i < n; i++)
{
array[i] = int.Parse(Console.ReadLine());
}
// Print the array
for (int index = 0; index < n; index++)
{
Console.WriteLine("Element[{0}] = {1}", index, array[index]);
}
Console.Read();
}
}
}