Question: Write a program that takes an input array of integers and prints the elements in reverse order.

Requirements:

  1. Define a function named printReverse that takes two parameters: an integer array (arr) and its size (size).
  2. The function should iterate through the array in reverse order and print each element.
  3. The program should prompt the user to enter the size of the array and its elements.
  4. Use dynamic memory allocation to create an array of the specified size.
  5. After printing the array in reverse order, deallocate the dynamically allocated memory.

Example Output:

Enter the size of the array: 5
Enter the elements of the array:
Element 0: 1
Element 1: 2
Element 2: 3
Element 3: 4
Element 4: 5
The elements in reverse order are:
5 4 3 2 1

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int main() {
    vector<int> arr; 
    int sizeOfArray; 
    int num;
    cout << "Enter the size of the array: ";
    cin >> sizeOfArray; 
    for(int i = 0; i < sizeOfArray; i++){
        cout << "Element " << i <<": "; 
        cin >> num; 
        arr.push_back(num); 
    } 
    reverse(arr.begin(), arr.end()); 
    cout << "The elements in reverse order are: "; 
     for(int i = 0; i < sizeOfArray; i++){
        cout << arr[i] << " "; 
    } 

}