Kat H.

asked • 05/10/21

Square Array. The existing codetries to make use of a function void squareArray(const int array[], int destination[], int size).

The existing codetries to make use of a function void squareArray(const int array[], int destination[], int size). This function should take each of the size elements from array, square the element, and place the answer into the same location in the destination array


i.e. if array is {1 2 3 4} and size is 4, when your function returns, destination should be {1 4 9 16}.


Code:


#include <iostream>


using namespace std;



//Do not modify anything on or above the line below this

//YOUR_CODE_BELOW



//YOUR_CODE



//YOUR_CODE_ABOVE

//Do not modify anything on or below the line above this


int main()

{

int NUM_VALUES; //cheating to make this flexible

cin >> NUM_VALUES;


int values[NUM_VALUES];

//Read in values

for(int i = 0; i < NUM_VALUES; i++) {

cin >> values[i];

}


int squares[NUM_VALUES];


//Call your function

squareArray(values, squares, NUM_VALUES);


for(int i = 0; i < NUM_VALUES; i++) {

cout << squares[i] << " ";

}


return 0;

}

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.