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]);
2
  • you can use stack. Commented May 6, 2018 at 14:27
  • divide by 2 ;-) Commented May 6, 2018 at 14:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.