Q:

Write C++ program to find reverse of an array

0

Write C++ program to find reverse of an array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.

#include <iostream>
#define MAX_SIZE 100 //Maximum size of the array
using namespace std;
 
int main() {
int array[MAX_SIZE];
int size, i;
 
  // Reading size of array
  cout<<"Enter size of the array: ";
  cin>>size;
 
  // Reading array elements
  cout<<"Enter elements in array: ";
    for (i = 0; i < size; i++) {
    cin>>array[i];
  }
 
  //Print array in reversed order
 cout<<"\nArray in reverse order: ";
    for (i = size - 1; i >= 0; i--) {
    cout<<"\t"<< array[i];
  }
 
   return 0;
}

Result:

Enter size of the array: 5

Enter elements in array: 1

2

3

4

5

Array in reverse order:         5       4       3       2       1

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C++ program to left rotate an array... >>
<< Write C++ program to put even and odd elements of ...