Write a C++ program to Reverse the given array in which the elements are entered by the user during run-time of the program.

program Code:
#include<iostream>
using namespace std;
int main()
{
int a[50],b[50];
int i,j,n;
cout<<"How many elements you want to enter into the array : ";

cin>>n;
cout<<endl;
cout<<"Enter elements into the array: ";
for(i=0; i<n ;i++)
{
cin>>a[i];
}
cout<<endl;
cout<<"Reverse of give array is : ";
for(i=n-1,j=0; i>=0;i--,j++)
{
b[i]=a[j];
}
for(i=0; i<n ;i++)
{
cout<<b[i];
}
return 0;
}


The program output is tested on www.jdoodle.com

Output:
How many elements you want to enter into the array : 8
Enter elements into the array: 1 3 5 2 4 5 2 1 
Reverse of give array is : 1 2 5 4 2 5 3 1


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: