//Diego Martinez CSC5 Chapter 9, P.537,#10
/*******************************************************************************
*
* ______________________________________________________________________________
*
*
*
*
* Computation is based on the Formula:
*
*
*
*______________________________________________________________________________
* INPUT
*
*
*
* OUTPUT
*
*
*
*******************************************************************************/
#include <iostream>
using namespace std;
// Function prototype
int* reverseArray(int arr[], int size);
int main()
{
// Original array
int numbers[] = {10, 20, 30, 40, 50};
int size = 5;
// Call function and store returned pointer
int* reversed = reverseArray(numbers, size);
// Display original array
cout << "Original Array: ";
for (int i = 0; i < size; i++)
{
cout << numbers[i] << " ";
}
cout << endl;
// Display reversed copy
cout << "Reversed Copy: ";
for (int i = 0; i < size; i++)
{
cout << reversed[i] << " ";
}
cout << endl;
// Free dynamically allocated memory
delete[] reversed;
return 0;
}
// Function definition
int* reverseArray(int arr[], int size)
{
// Dynamically allocate new array
int* newArray = new int[size];
// Copy elements in reverse order
for (int i = 0; i < size; i++)
{
newArray[i] = arr[size - 1 - i];
}
// Return pointer to new array
return newArray;
}