The logic to reverse an array without using another array in C program is to swap 1st element with the last element, then the 2nd element with the 2nd last element, then 3rd, 4th… until we reach the middle element.

Reverse array without array

We will use while loop with condition i<j. Because if i == j, then it means it is the middle element of the array and the middle element doesn’t need to be swapped.

Steps to Reverse an Array in C

  1. Initialize an array with values.
  2. Set i=0 for pointing 1st element and j= length – 1 for pointing the last element in the array.
  3. Run while loop with the condition i < j.
  4. Inside loop swap ith element with the jth element in the array.
  5. Increment i and Decrement j.
  6. End Loop.
  7. Display array and end program.

Reverse Array in C without using Another Array

Output

C Program to reverse array without using another array

That’s we need to write to reverse an array in C. If you didn’t understand any part of the program then comment below.

Leave a Reply

Close Menu