4. C++ program to reverse the element of an integer 1-D array

#include<iostream>
using namespace std;

int main()
{
// Reverse of an array
    int num, temp;
    cin>>num;

    int arr[num];
    for(int i = 0;i<num ;i++)
        cin>>arr[i];

    for(int i = 0, j=num-1; i<j;i++,j--)
    {
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;

    }
    cout<<"\nElements of an array after Reverse :: \n";
    for(int i = 0;i<num ;i++)
        cout<<arr[i]<"\t";


    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s