Reverse an Array in C++

Google Advertisements

Prev Tutorial Next Tutorial

C++ Program to Reverse an Array

Array store all data in array on the basis of index. For reverse an array element you nedd to interchange elements of array on the basis of index value. .

C++ Program to Reverse an Array

#include<iostream.h>
#include<conio.h>

 void main()
  {
   int a[20],b[20],i,j,n;
   clrscr();
   cout<<"How many elements you want to enter: ";
   cin>>n;
   cout<<"Enter any "<<n<<" elements in Array: ";
   for(i=0; i<n ;i++)
   {
   cin>>a[i];
   }
   cout<<"Reverse of Array: ";

   for(i=n-1,j=0; i>=0;i--,j++)
   {
    b[i]=a[j];
   }
   for(i=0; i<n ;i++)
   {
   cout<<b[i];
   }
  getch();
  }

Output

How many elements you want to enter : 5
Enter any 5 elements in Array: 
1 4 2 7 5
Reverse of Array: 5 7 2 4 1

Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Media.net Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: [email protected] or 9999595223 Try this Keyword C++ Programs