Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that accepts an array of integers and the array\'s size as argu

ID: 3770151 • Letter: W

Question

Write a function that accepts an array of integers and the array's size as arguments. The function should create a copy of the array, except that the values should be reversed in the copy. The function should return a pointer to the new array. Write a main function which uses this function and asks users for values in an array, outputting the reversed array afterwards

Sample output: How many numbers do you have in your array? 3

Enter value #1: 51

Enter value #2: 16

Enter value #3: 97

97 16 51

using c++

Explanation / Answer

Here is the code for you. If you have any further queries, just get back to me.

#include <iostream>
using namespace std;
void ArrayReverse(int Array[], int size)   //Reverses the array.
{
for(int i = 0; i < size/2; i++)
{
int temp = Array[i];
Array[i] = Array[size-1-i];
Array[size-1-i] = temp;
}
}
void printArray(int Array[], int size)   //Prints the array.
{
for(int i = 0; i < size; i++)
cout<<Array[i]<<" ";
cout<<endl;
}
int main()
{
int Array[20], num;
cout<<"How many numbers do you have in your array? ";
cin>>num;       //Reads the size of array.
for(int i = 0; i < num; i++)   //Reads the array elements.
{
cout<<"Enter value #"<<i+1<<": ";
cin>>Array[i];
}
printArray(Array, num);   //Prints the array before reversing.
ArrayReverse(Array, num);   //Reverses the array.
printArray(Array, num);        //Prints the array after reversing.
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote