C++ Program to reverse an array elements


In this program, You will learn how to reverse an array elements in C++.


List is: 10 20 30 40 50 60

After: 60 50 40 30 20 10


Example: How to reverse an array elements in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int arr[10];
    int i, j, s, temp;

    cout << "Enter size of an Array :";
    cin>>s;

    cout << "\nEnter Array Elements :";
    for (i = 0; i < s; i++) {
        cin >> arr[i];
    }

    j = s - 1;
    for (i = 0; i < j; i++) {
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
        j--;
    }

    cout << "\nAfter Reverse Array Elements is:";
    for (i = 0; i < s; i++) {
        cout << arr[i] << " ";
    }

    return 0;
}

Output:

Enter size of an Array :5
Enter Array Elements :10 20 30 40 50
After Reverse Array Elements is:50 40 30 20 10