Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- //[1, 2, 3, 4, 5] -> exchange 2 -> result: [4, 5, 1, 2, 3]
- int[] arr = { 1, 2, 3, 4, 5 };
- int[] exchanged = new int[arr.Length];
- int index = 2;
- for (int i = 0, j = index + 1; i < arr.Length; i++, j++)
- {
- exchanged[i] = arr[j];
- if (j==arr.Length-1)
- {
- j = -1;
- }
- }
- Console.WriteLine(string.Join(' ', exchanged));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment