Knowee
Questions
Features
Study Tools

.Suppose multidimensional arrays P and Q are declared as P (-2: 2, 2: 22) and Q (1: 8, -5: 5, -10: 5) stored in column major order(i) Find the length of each dimension of P and Q(ii) The number of elements in P and Q

Question

.Suppose multidimensional arrays P and Q are declared as P (-2: 2, 2: 22) and Q (1: 8, -5: 5, -10: 5) stored in column major order(i) Find the length of each dimension of P and Q(ii) The number of elements in P and Q

🧐 Not the exact question you are looking for?Go ask a question

Solution

(i) The length of each dimension of P and Q can be found by subtracting the lower bound from the upper bound and adding 1 (since both bounds are inclusive).

For P:

  • The first dimension ranges from -2 to 2, so its length is 2 - (-2) + 1 = 5.
  • The second dimension ranges from 2 to 22, so its length is 22 - 2 + 1 = 21.

For Q:

  • The first dimension ranges from 1 to 8, so its length is 8 - 1 + 1 = 8.
  • The second dimension ranges from -5 to 5, so its length is 5 - (-5) + 1 = 11.
  • The third dimension ranges from -10 to 5, so its length is 5 - (-10) + 1 = 16.

(ii) The number of elements in P and Q can be found by multiplying the lengths of their dimensions.

For P, the number of elements is 5 * 21 = 105.

For Q, the number of elements is 8 * 11 * 16 = 1408.

This problem has been solved

Similar Questions

Using ndim we can find ?We can find the dimension of the arraySize of arrayOperational activities on MatrixNone of the above

Suppose you have an array defined in the following way: int myArray[][] = {{16, 72}, {18, 24}, {5, 4}, {19, 3}}; What are the correct dimensions of this array?a.)2 x 4b.)4 x 2c.)8 x 1d.)3 x 3

Which of the following arrays is a two dimensional (2-D) array?89[1,2,3,4][1,2,3],[3,4,5],[1,3,4][[2 3 5][ 4 5 6][4 5 6]]

You are given a matrix and an array. For each row of the given matrix, for each element of that row, check if it is present in the given array. Print the count of elements present for every row.Input FormatThe first line of input contains N, M - the size of the matrix. It is followed by N lines each containing M integers - elements of the matrix. The next line of the input contains the A - the size of the array. The next line of the input contains the array elements.Output FormatFor each row, print the count of the number of elements present, separated by a new line.Constraints1 <= N, M, A <= 100-100 <= mat[i][j], ar[i] <= 100ExampleInput3 45 9 -2 2-3 4 1 92 -2 1 -255 1 -2 2 6Output314ExplanationThe first row of the matrix is (5 9 -2 2), out of this, 3 elements (5 -2 2), except 9, are present in the given array (5 1 -2 2 6)The second row of the matrix is (-3 4 1 9), out of this, only 1 is present in the given array (5 1 -2 2 6)The third row of the matrix is (2 -2 1 -2), all the 4 elements are present in the given array (5 1 -2 2 6)

What is the index range for a row in a 2D array with dimensions 4x2?

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.