C++ Program to Reverse the Elements of an Array

C++ Program to Reverse the Elements of an Array The article is a lively article because it contains interesting information and your favorite.   

C++ Program to Reverse the Elements of an Array

C++ Program to Reverse the Elements of an Array

#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;
}

Read Also: C Program to Build a Multiplayer Tic-Tac-Toe GUI Game

Final Words

I hope you find the article C++ Program to Reverse the Elements of an Array used. The reason is that we have told you all the information through this article in a way that you can understand. And if you have any doubts, you can express your doubts through the comment box. We also ask that you help share this article with your friends.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment