Reverse Array Elements Using Function in C++

Google Advertisements

Prev Tutorial Next Tutorial

C++ Program to Reverse Array Elements Using Function

An array is used to store a collection of data, but it store same type of data. In simple word Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. Here we write simple code for reverse array elements using function in C++.

Reverse Array Elements Using Function in C++

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

void Reverse_Array(int array[],int size);

void main()
{
int i,a[10],size;
clrscr();
cout<<"Enter size of Array ( Max:10 ): ";
cin>>size;
cout<<"\nEnter any "<<size<<" elements: \n";

for(i=0; i<size; i++)
{
 cin>>a[i];
}

cout<<"\nStored Data in Array: \n\n";

for(i=0;i<size;i++)
{
cout<<" "<<a[i]<<" ";
}
// Calling Reverse Array Values Function
Reverse_Array(a,size);
cout<< "\n\nReversed Array Elements are: \n\n";
 for(i=0;i<size;i++)
 {
  cout<<" "<<a[i]<<" ";
 }
cout<<"\n";
getch();
}

//------Reverse Array Function---------------

void Reverse_Array(int array[],int size)
{
int temp;
size--;
for (int i=0;size>=i;size--,i++)
{
temp=array[i];
array[i]=array[size];
array[size]=temp;
}
}

Output

Enter size of Array ( Max:10 ): 5
Enter any 5 elements
4
7
8
3
9
Stored Data in Array:
4 7 8 3 9
Reversed Array Elements are:
3 4 7 8 9

Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. If you want to post your article on our website/FB Group/FB Page please contact on hitesh.xc@gmail.com or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Path variable is set for providing path for all Java tools like java, javac, javap, javah, jar, appletviewer which are used in java programming. All these tools are available in bin folders so we set path upto bin folders.

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar.

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user.

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects.

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483