1. 程式人生 > >數組元素交換位置

數組元素交換位置

nbsp stat ons ole 數組元素 con ring arr 組元

static void Main(string[] args)

{

int[] arr = { -2,5,-6,9,3,7};

Wz(arr);

}

public static void Wz(int[] arr) {

for (int i = 0; i < arr.Length/2; i++)

{

int arrs = arr[i];

arr[i] = arr[arr.Length - i - 1];

arr[arr.Length - i - 1] = arrs;

}

for (int i = 0; i < arr.Length; i++)

{

Console.Write(arr[i]+"\t");

}

Console.ReadKey();

}

輸出: 7 3 9 -6 5 -2

數組元素交換位置