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

1. Given a 2-by-5 integer array X, answer the following questions: (program is n

ID: 3817230 • Letter: 1

Question

1. Given a 2-by-5 integer array X, answer the following questions: (program is not required)

a. Write a definition (array declaration) for X

b. How many rows and columns does X have?

c. How many elements does X have?

d. Write the names of all the individual elements in the second row of array X (hint: see slide 13 of lecture 9)

e. Write the names of all the elements in the third column of array X

f. Write a single statement that sets the element of X in row 1 and column 2 (in the way C counts, not as humans do) to the value zero

Explanation / Answer

If we consider the language is c++

a. Write a definition (array declaration) for X

int x[2][5];

where 2 represent the rows

and 5 represent the columns

b. How many rows and columns does X have?

there are 2 rows and 5 columns.

Here is 2 by 5 representation:

c. How many elements does X have?

There are 2 * 5 = 10 elements in x

d. Write the names of all the individual elements in the second row of array X (hint: see slide 13 of lecture 9)

for(int i = 0 ; i < 5 ; i++)
{
cout << X[1][i] ;
}

print all the 2nd row element .

e. Write the names of all the elements in the third column of array X

for(int i = 0 ; i < 2 ; i++)
{
cout << X[i][2] ;
}

print all the 3nd column element .

f. Write a single statement that sets the element of X in row 1 and column 2 (in the way C counts, not as humans do) to the value zero

X[0][1] = 0;

set data Test to row 1 and column 2