Topic Wise Solved Problems Question – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
CPP All :Topicwise Exam Questions: two-dimensional-arrays-and-matrices siteicon
Sum of middle row of 2D Matrix 2

Write definition for a function ADDMIDROW(int MAT[][10],int R,int C) in C++, which finds sum of the middle row elements of the matrix MAT (Assuming C represents number of Columns and R represents number of rows, which is an odd integer). For example, if the content of array MAT having R as 3 and C as 5 is as follows:

1 2 3 4 5
2 1 3 4 5
3 4 1 2 5

The function should calculate the sum and display the following:
Sum of Middle Row: 15

CBSE12D-2017

Function to show middle row and middle column of a 2D Array 3

Write definition for a function SHOWMID(int P[][5],int R,int C) in C++ to display the elements of middle row and middle column from a two dimensional array P having R number of rows and C number of columns.
For example, if the content of array is as follows:

115 112 116 101 125
103 101 121 102 101
185 109 109 160 172

The function should display the following as output :
103 101 121 102 101
116 121 109

CBSE12D-2016

Reversing each column in a 2D Matrix 3

Write a function REVCOL (int P[][5], int N, int M) in C++to display the content of a two dimensional array, with each column content in reverse order.
Note: Array may contain any number of rows.
For example, if the content of array is as follows:

15 12 56 45 51
13 91 92 87 63
11 23 61 46 81

The function should display output as:

11      23     61    46    81
13      91     92    87    63
15      12     56    45    51
CBSE12D-2015


Random Number Based Guessing of output of a 2D Array printing 2

Look at the following C++ code and find the possible output(s) from the
options (i) to (iv) following it. Also, write the maximum values that can
be assigned to each of the variables N and M.

Note:

  • Assume all the required header files are already being included in
    the code.
  • The function random(n) generates an integer between 0 and n-1
void main()
{
  randomize();
  int N=random(3),M=random(4);
  int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
  for(int R=0; R<N; R++)
  {
    for(int C=0; C<M; C++)
      cout<<DOCK[R][C]<<" ";
    cout<<endl;
  }
}

(i)
1 2 3
2 3 4
3 4 5

(ii)
1 2 3
2 3 4

(iii)
1 2
2 3

(iv)
1 2
2 3
3 4

CBSE12A-2017

Sum of middle column of 2D Matrix 2

Write a definition for a function SUMMIDCOL(int MATRIX[][10],int N,int M) in C++, which finds the sum of the middle column’s elements of the MATRIX (Assuming N represents number of rows and M represents number of columns, which is an odd integer).
Example: if the content of array MATRIX having N as 5 and M as 3 is as follows:

1 2 1
2 1 4
3 4 5
4 5 3
5 3 2

The function should calculate the sum and display the following:
Sum of Middle Column: 15

CBSE12A-2017

Function to display middle column of 2D Array 3

Write definition for a function DISPMID(int A[][5],int R,int C) in C++ to display the elements of middle row and middle column from a two dimensional array A having R number of rows and C number of columns.
For example, if the content of array is as follows:

215 912 516 401 515
103 901 921 802 601
285 209 609 360 172

The function should display the following as output
103 901 921 802 601
516 921 609

CBSE12A-2016

Reversing each row of a 2D array 3

Write a function REVROW(int P[][5],int N, int M) in C++ to display the content of a two dimensional array, with each row content in reverse order.
For example, if the content of array is as follows:

15 12 56 45 51
13 91 92 87 63
11 23 61 46 81

The function should display output as:
51 45 56 12 15
63 87 92 91 13
81 46 61 23 81

CBSE12A-2015