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

Program Code:
#include<iostream>
using namespace std;
int main()
{
int array[25];
int number;
int temp, i,j;
cout<<"Enter number of elements you want to insert in array : ";
cin>>number;
cout<<endl;
for(i=0;i<number;i++)
{
cout<<"Element "<<i+1<<":";
cin>>array[i];
cout<<endl;
}
for(i=0,j=number-1;i<number/2;i++,j--)
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
cout<<"Reverse array of the given array is : "<<endl;
for(i=0;i<number;i++)
cout<<array[i]<<" ";
return 0;
}

The program code is tested on www.jdoodle.com
Output:
Enter number of elements you want to insert in array : 5
Element 1: 11
Element 2: 22
Element 3: 33
Element 4: 44
Element 5: 55
Reverse array of the given array is : 
55 44 33 22 11 


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: