Example 66: Reverse an Array
Learn how to reverse the elements of the array.
We'll cover the following
Problem
Write a program to reverse the contents of a 1D array.
Example
Suppose two arrays named arr and arr1 contains the following elements:
arr[ ] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
arr1[ ] = 1, 2, 3, 4, 5
The table below shows the respective array elements once it has been reversed.
Input (arr, size) | Output |
---|---|
arr, 10 | 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 |
arr1, 5 | 5, 4, 3, 2, 1 |
Demonstration
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.