Answer to Question #252197 in C++ for khangphanana

Question #252197

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.


1
Expert's answer
2021-10-16T11:02:31-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS