
Arrays Warm Up CPSC 220.
1. Declare an array named cosine with 360 elements each of type double.
2. Suppose the variable d represents the measure of an angle in degrees. Then its
measure in radians is d/180.0. Write the statements necessary so that each of the
elements of the elements holds the cosine of the corresponding angle. That is,
cosine[d] is the trigonometric cosine of the angle whose measure is d.
3. Given a triangle with sides a, b and c and angle X, the Law of Cosines states
c2 = a2 + b2 - (2)(a)(b)(cos X).
Write the code to read in two doubles, representing the length of two of the sides of a
triangle, the measure of the angle X., and then to determine the length of the third
side using the array cosine.
4. How many elements are in each of the following arrays?
a. int x[27];
b. const int base = 10;
int y[base+5];
c. int z[100][100][100][100];
5. What’s wrong with following code segment?
int pep[100];
for( int index =1; index <=100; index++)
pep[index] = 0;
6. What’s wrong with the following code segment?
int pep[2][3] = {
{1,2},
{5,9},
{0,-3}
};
7. Given the following declaration:
int pep [12] [15];
a. Write a loop to print the first row of the array on one line on cout.
b. Write a loop to print the first column on the array on one line on cout.
c. Write a loop to print the first seven rows of the array, each on a single line.
d. Write a loop to print the entire array backwards and upside down, so that
the last line appears first, with last column on the left.