Reverse the array in C++ by R4R Team

program:

#include < iostream>
using namespace std;
int main()
{
int a[20],b[20],i,n;
cout<<"Number of element in array?"<< endl;
cin>>n;
cout<<"Enter element in array"<< endl;
//input in first array
for(i=0;i< n;i++)
{
cin>>a[i];
}
//Now reverse and copy in another array
for(i=0;i< n;i++)
{
b[i]=a[n-i-1];
}
//Now display second array
cout<<"Reverse Array is: "<< endl;
for(i=0;i< n;i++)
{
cout<< b[i]<<" ";
}
return 0;
}


output-

Number of element in array?
5
Enter element in array
4 3 1 5 2
Reverse array is:
2 5 1 3 4




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!