Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. using System;
  2.  
  3. class MainClass
  4. {
  5. public static void Main (string[] args)
  6. {
  7. int[] myArray = new int[]{1,2,3,4,5};
  8. int[] newArray = new int[myArray.Length];
  9.  
  10. // 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.
  11. for(int i = 0; i < myArray.Length;i++)
  12. {
  13. newArray[i] = myArray[(myArray.Length - 1) - i];
  14. }
  15.  
  16. // print out the reversed array
  17. for(int i = 0; i < newArray.Length;i++)
  18. {
  19. Console.WriteLine (newArray[i]);
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement