In: Computer Science
char table[7][9];
which of the following stores the character 'B' into the fifth row and second column of the array?
A) table[5] = 'B';
B) table[2][5] = 'B';
C) table[5][2] = 'B';
D) table[1][4] = 'B';
E) table[4][1] = 'B';
int arr[10][20];
int i, j;
for (i = 0; i < 10; i++)
for (j = 0; j < 20; j++)
// Statement is missing here
What is the missing statement?
A) arr[j+1][i+1] = 0;
B) arr[i-1][j-1] = 0;
C) arr[i+1][j+1] = 0;
D) arr[i][j] = 0;
E) arr[j][i] = 0;
3. Given this nested For loops
for (i = 0; i < M; i++)
for (j = 0; j < N; j++)
cout << arr[i][j];
what is the appropriate declaration for arr?
A) int arr[M+N];
B) int arr[M+1][N+1];
C) int arr[M][N];
D) int arr[N][M];
E) int arr[N+1][M+1];
float alpha[5][50];
float sum = 0.0;
which one computes the sum of the elements in row 2 of alpha?
A) for (i = 0; i < 50; i++)
sum = sum + alpha[2][i];
B) for (i = 0; i < 5; i++)
sum = sum + alpha[2][i];
C) for (i = 0; i < 50; i++)
sum = sum + alpha[i][2];
D) for (i = 0; i < 5; i++)
sum = sum + alpha[i][2];
int numberArray[9][11];
Write a statement that assigns 130 to the first column of the second row of this array.
Values is a two-dimensional array of floats that include 10 rows and 20 columns. Write a
code that sums all the elements in the array and stores the sum in the variable named total.
Ans 1: E) table[4][1] = 'B';
The first half is used to get to the 5th row(4th index) and second part is used to get to the 2nd column(1 st index).
Ans 2: D) arr[i][j] = 0;
Since, we the row index values ranges from 0 to 9 and the column index value ranges from 0 to 19.
Ans 3: C) int arr[M][N];
Since, we the row index values ranges from 0 to M-1 and the column index value ranges from 0 to N-1.
Ans 4: The options to this question are incorrect. Since, we need to access the second row (i.e., 1st index considering arrays are 0 index by default). The correct answer is
for (i = 0; i < 50; i++)
sum = sum + alpha[1][i];
Ans 5:
Write a statement that assigns 130 to the first column of the second row of this array:
=> numberArray[1][0] = 130;
Write a statement which will assign 18 to the last column of the last row of this array.
=> numberArray[8][10] = 18;
Ans 6:
float numarray[10][20];
float total = 0;
for (int i=0; i<10; i++){
for (int j= 0; j<20; j++){
total += numarray[i][j];
}
}