I need some help on Arrays. Here is the project I'm working on.
Write a program to read the items into two arrays, x and y, of size 20.
Store the products of corresponding pairs of elements of x any in a third away, z, also of size 20. Print a three-column table that displays the arrays x, y, and z. Then compute and print the square root of the sum items Z.

Now I have some of the code done and what I need advice in is how to take the numbers of arrays x and y, add them, make the square root and to store them in the new array called Z.

``````// Warren Culp
// 9/27/09
// Prof. Yoa

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{

int X[20], Y [20];

cout << "Please enter 20 numbers for row 1" << endl;

for(int count = 0; count < 20; count++)
{
cin >> X[count];
}
cout << endl;
cout << "Please enter 20 numbers for row 2" << endl;

for (int count = 0; count < 20; count++)
{
cin >> Y[count];
}

cout << "The contents of both arrays are" << endl;
cout << endl;
cout << "Array X" << " " << "Array Y" << endl;
cout << "---------------------------" << endl;
for (int count = 0; count < 20; count++)
{
cout << X[count] << " " << Y[count];
}
return 0;

}``````
4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by StuXYZ

Take a look at function sqrt

Declare a new array called Z[20].
Then use the following code to add the corresponding numbers.

``````for (int count = 0; count < 20; count++)
{
Z[count]=X[count]+Y[count];
cout<<Z[count]<<endl;
}``````

This code says:
Take the values at position 'count' of arrays X and Y and add them together. Then place that value into position 'count' of array Z.