0

I tried this and the output is 5 4 3 4 5 instead of 5 4 3 2 1.

for (int i = 0; i < numbers.Length;i=i+1)
        {
            int tmp = numbers[i];
            numbers[i] = numbers[numbers.Length - i - 1 ];
            numbers[numbers.Length - i - 1 ] = tmp;
            Console.WriteLine(numbers[i]);
Meh234
  • 1
  • 1
  • 1

1 Answers1

0

My first question would be why not just use Array.Reverse. But in any case, your bug is in the exit condition of your for loop. You need to stop at numbers.Length/2 or you just swap everything back.

Adam G
  • 1,283
  • 1
  • 6
  • 15