Reverse order of elements of an array

Reverse order of elements of an Array


Iterative way

Initialize start and end indexes

start = 0, end = n1

In a loop, swap arr [start] with arr [end] and change start and end as follows.

start = start + 1, end = end – 1.

Recursion way

Initialize start and end indexes

start = 0, end = n1.

Swap arr [start] with arr[end].

Recursively call reverse for rest of the array.

For example if a is an array of integers with three elements such that

a [0] = 1

a [1] = 2

a [2] = 3

Then on reversing the array will be

a [0] = 3

a [1] = 2

a [0] = 1

Qus. 1 : To reverse the order of elements in an array, the algorithm must swap elements between:

  1. Adjacent indices
  2. First and last, second and second-last, etc.
  3. Random indices
  4. Even indices only

Programs

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad