Computer Science, asked by MohammedAamir8220, 1 year ago

2d array (square matrix)on the basis 1. to sum elements of each diagonal display it on screen 2. to display only middle row and middle column 3. to display only lower half part of matrix c++

Answers

Answered by Raghav3333
2

So, far we have seen one dimensional arrays. Now we will see two dimensional array also known as matrix, which is another useful data structure. Consider the declaration below :

int mat [ 3 ][ 4 ];

We have declared a two dimensional array or matrix with 3 rows and 4 columns. We can store 3 x 4 = 12elements in this matrix. Each element is stored in a cell which can be accessed using the combination of 
row index and column index. Initialization of a 2D array is shown below :

InitializationIndexingint mat[3][4] = { { 17, 23, 15, 19 }, { 44, 29, 52, 76 }, { 21, 63, 35, 57 } };
17 [ 0, 0 ]23 [ 0, 1 ]15 [ 0, 2 ]19 [ 0, 3 ]44 [ 1, 0 ]29 [ 1, 1 ]52 [ 1, 2 ]76 [ 1, 3 ]21 [ 2, 0 ]63 [ 2, 1 ]35 [ 2, 2 ]57 [ 2, 3 ]

We can see how the above initialization statement in the left builds a matrix shown in the right. Every element is stored in a cell which has a index shown as subscript of each element. For e.g, 52 is stored in a cell with index 
[ 1, 2 ] where 1 denotes the row number ( index ) and 2 denotes the column number ( index ). Please note that both row and column index starts with 0.
Following program inputs a matrix from user and displays it :

12345678910111213141516171819202122232425#include<iostream>using namespace std;int main() {   int mat[3]
Similar questions