c++

C++ Program to Reverse the Elements of an Array Full Project For Beginners


 

Welcome folks today in this blog post we will be reversing the elements of an array in c++ All the full source code of the application is shown below.

 

 

 

 

 

 

In order to get started you need to make a app.cpp file and copy paste the following code

 

 

app.cpp

 

 

#include<iostream>
using namespace std;
void reverseArray(int a [], int n)
{
  int i,j,temp;
  for(i=0,j=n-1;i<n/2;i++,j--)
  {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
  }
}
void printArray(int a[], int n)
{
  int i;
  for(i=0;i<n;i++)
  {
    cout<<a[i]<<" ";
  }
}
int main()
{
  int a[100],n,i;
  cout<<"Enter n value n";
  cin>>n;
  cout<<"Enter array elements n";
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  cout<<"n "<<"Array elements before reversing :n";
  printArray(a,n);
  reverseArray(a,n);
  cout<<"Array elements after reversing :n";
  printArray(a,n);
  return 0;
}

 

Similar Posts:

    None Found

Leave a Reply

Your email address will not be published. Required fields are marked *