ProgrammingVery hard
int a[3][3] = {{2,7,6},{9,5,1},{4,3,8}}; Are all of the row sums, column sums and both diagonal sums equal to 15?
- A. No, the first row sums to 15 but the diagonals do not
- B. No, the columns do not all sum to 15
- C. Yes, it is a magic square
- D. No, the rows sum to 15 but the main diagonal is 14
Correct answer: C. Yes, it is a magic square
The rows, columns and both diagonals of this matrix each add to 15, so it is a magic square.
More C Programming questions
- Row-major storage of int a[4][5] means a[i][j] is at flat index i 5 + j. What flat index holds a[3][2]?
- int a[2][3] with a pointer p = &a[0][0]. Which expression gives the number of elements between a[0][0] and a[1][2]?
- The sum of the elements of a[i][j] = i j over the 4 x 4 matrix equals what?
- Which statement about matrix multiplication in C is correct for an m x k matrix times a k x n matrix?
- Sum of a 2 x 2 window of m[i][j] = i + j starting at (1,1) in a 4 x 4 grid, i.e. m[1][1] + m[1][2] + m[2][1] + m[2][2]. What is the value?
- In a 2D array with int a[5][5], what is the total number of bytes in one row when int is 4 bytes?