Login


Lost your password?

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


Shop
CPP All : Two dimensional arrays and Matrices
Concept Learning Code Sheets

Student Marks 3 Subjects 2D Array #1618

Showing how multiple students marks in multiple subjects can be stored and used in 2D Array.

Matrix addition 2D with pre-initialised values #1635

Adding two 2D integer matrix into a third matrix of same size with values pre-initialised at the beginning.

Displaying a 2D Array #1887

Displaying a 2 dimensional array which is pre-filled with initialised data in the row column format.

Sum of all members of 2D array #1889

Finding the sum of all members of a matrix having number values.

Sum of each row and all members of 2D array #1891

Finding the sum of each row and all members of a matrix having number values.

Sum of each row and row addition of 2D array #1893

Finding the sum of each row and then sum of all members by adding each row addition of a matrix having number values.

Print square of a 2D array in row-column format #1895

Printing a 2D matrix with each value squared in a proper rows and column format that looks like a matrix.

Solved Problems

Product of single 2D matrix members #2229

Write a program to find the product of all members of any 2D Matrix whose siz

Write a program to find the product of all members of any 2D Matrix whose size and data member values are given by the user. Assume that maximum size of matrix can be 10×10.

Search in 2D Array #2325

Write a program to search the presence of user given input number in a 2 dim

Write a program to search the presence of user given input number in a 2 dimensional array of
3 rows and 4 colums preinitialised with some numbers. The search output should be row/col of search location if found, else report “Not Found”. Assume that all members of array contain different values.

Swapping first and last row #5000

Write a user-defined function swap_row(int ARR[ ][3],int R,int C) in C++ to

Write a user-defined function swap_row(int ARR[ ][3],int R,int C) in C++ to swap the first row values with the last row values:

For example if the content of array is –
10 20 30
40 50 60
70 80 90

Then after function call the content of array would be

70 80 90
40 50 60
10 20 30

Swapping first and last column #5004

Write a user-defined function swap_col(int ARR[ ][3],int R,int C) in C++ to

Write a user-defined function swap_col(int ARR[ ][3],int R,int C) in C++ to swap the first column values with the last column values:

For example if the content of array is –
11 12 13
21 22 23
31 32 33

Then after function call the content of array would be

13 12 11
23 22 21
33 32 31

Printing Top Diagonal Half of Square Matrix Including Diagonal Members. #5274

( As In Exam - CBSE12A-2018 )

Write definition for a function UpperHalf(int Mat[4][4]) in C++, which displa

Write definition for a function UpperHalf(int Mat[4][4]) in C++, which displays the
elements in the same way as per the example shown below.

For example, if the content of the array Mat is as follows:

25 24 23 22
20 19 18 17
15 14 13 12
10  9  8  7

The function should display the content in the following format:

25 24 23 22
20 19 18
15 14
10

2-D Array Element Address Calculation #5281

( As In Exam - CBSE12A-2018 )

Let us assume Data[20][15] is a two dimensional array, which is stored in the

Let us assume Data[20][15] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 2 bytes, find the address of the element Data[10][5], if the element Data[15][10] is stored at the memory location 15000.

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

( As In Exam - CBSE12A-2017 )

Look at the following C++ code and find the possible output(s) from the

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

Collecting 2D Array members, Doubling and Printing #5372

Write a program to collect members of a 2-D integer array in A[3][3] form. Do

Write a program to collect members of a 2-D integer array in A[3][3] form. Double value of each member and then print the array in matrix form

Sum of middle column of 2D Matrix #5769

( As In Exam - CBSE12A-2017 )

Write a definition for a function SUMMIDCOL(int MATRIX[][10],int N,int M) in

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

2-D Array Element Address Calculation #5772

( As In Exam - CBSE12A-2017 )

ARR[15][20] is a two-dimensional array, which is stored in the memory along t

ARR[15][20] is a two-dimensional array, which is stored in the memory along the row with each of its elements occupying 4 bytes. Find the address of the element ARR[5][15], if the element ARR[10][5] is stored at the memory location 35000.

2-D Array Element Address Calculation #5873

( As In Exam - CBSE12D-2015 )

A two dimensional array P[20] [50] is stored in the memory along the row wit

A two dimensional array P[20] [50] is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element P[10] [30],if the element P[5] [5] is stored at the memory location 15000.

Reversing each column in a 2D Matrix #5881

( As In Exam - CBSE12D-2015 )

Write a function REVCOL (int P[][5], int N, int M) in C++to display the cont

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

2-D Array Element Address Calculation #5959

( As In Exam - CBSE12A-2015 )

A two dimensional array ARR[50][20] is stored in the memory along the row wi

A two dimensional array ARR[50][20] is stored in the memory along the row with each of its elements occupying 4 bytes. Find the address of the element ARR[30][10], if the element ARR[10] [5] is stored at the memory location 15000.

Reversing each row of a 2D array #5964

( As In Exam - CBSE12A-2015 )

Write a function REVROW(int P[][5],int N, int M) in C++ to display the conten

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

Sum of middle row of 2D Matrix #6036

( As In Exam - CBSE12D-2017 )

Write definition for a function ADDMIDROW(int MAT[][10],int R,int C) in C++,

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

2-D Array Element Address Calculation #6039

( As In Exam - CBSE12D-2017 )

T[25][30] is a two dimensional array, which is stored in the memory along the

T[25][30] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 2 bytes, find the address of the element T[10][15], if the element T[5][10] is stored at the memory location 25000.


Code Sheets:7  Solved Problems:16 
×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Mult-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back