
Patrick B. answered 05/11/21
Math and computer tutor/teacher
void squareArray( const int array[], int destination[], int size)
{
for (int iLoop=0; iLoop<size; iLoop++)
{
destination[iLoop] = array[iLoop]*array[iLoop];
}
}
Kat H.
asked 05/10/21The 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;
}
Patrick B. answered 05/11/21
Math and computer tutor/teacher
void squareArray( const int array[], int destination[], int size)
{
for (int iLoop=0; iLoop<size; iLoop++)
{
destination[iLoop] = array[iLoop]*array[iLoop];
}
}
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.