Defines a function that stores the elements of an array of real numbers in reverse, declaring the function as: void reverse (double arr[], const int size, double*& rev). Write a main program using the above function.
#include <iostream>
using namespace std;
void reverse(double arr[], const int size, double*& rev) {
rev = new double[size];
for (int i=0; i<size; i++) {
rev[size-1-i] = arr[i];
}
}
int main() {
const int N = 5;
double arr[N] = {1.0, 2.0, 3.0, 4.0, 5.0 };
double* rev;
reverse(arr, N, rev);
cout << "Reverse array: ";
for (int i=0; i<N; i++) {
cout << rev[i] << " ";
}
cout << endl;
delete [] rev;
return 0;
}
Comments
Leave a comment