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

Simple declaration, value putting and direct value display from 2D array #7527

A simple code to declare a 2D array, direct value putting and value recall.

Initialising and Displaying a 2D Array #1887

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

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.

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.

Sum of primary diagonal members of a square matrix array #7519

Finding sum of primary diagonal (from left top to right bottom) members of a 2D of a square matrix array

Sum of primary diagonal members of a square matrix using 1 loop only #7521

Finding sum of primary diagonal (from left top to right bottom) members of a 2D of a square matrix array using one loop only

Exam Papers Problems

Printing Top Left 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

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

Function to display middle column of 2D Array #5668

( As In Exam - CBSE12A-2016 )

Write definition for a function DISPMID(int A[][5],int R,int C) in C++ to dis

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

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

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

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

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

( As In Exam - CBSE12D-2016 )

Write definition for a function SHOWMID(int P[][5],int R,int C) in C++ to dis

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

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

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


Code Sheets:10  Exam Paper Problems:8  Solved Problems:5 
×
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 2D Array Memory Addressing 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