Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MainClass
- {
- public static void Main (string[] args)
- {
- int[] myArray = new int[]{1,2,3,4,5};
- int[] newArray = new int[myArray.Length];
- // the first element is swapped with the last element, the second element is swapped with the next to last element, etc. with the middle element not actually changing.
- for(int i = 0; i < myArray.Length;i++)
- {
- newArray[i] = myArray[(myArray.Length - 1) - i];
- }
- // print out the reversed array
- for(int i = 0; i < newArray.Length;i++)
- {
- Console.WriteLine (newArray[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement