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

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com 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

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

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ 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 Try this Keyword C++ Programs