Skip to content

2d matrices

Arrays : 2D Matrices

Matrices are series of series of scalars, or series of vectors. In code, they are typically stored as an array of arrays.

int matrix[]= new int[3,3]

[
    [1,2,3],
    [4,5,6],
    [7,8,9]
]
Scalars

Scalars are simply numbers. For example, 2 is a scalar. So is 3.14159 and 1.618. And so is -273.15. Bonus points if you can figure out what those numbers are special for.

Vectors

Vectors are series of scalars. For example, [1, 3, 5, 7, 9] is a vector. You typically store vectors as an array.

2D Matrix

matrix_defn

Problem 1 - Print Row Wise Sum

row_wise_sum

Problem 2 - Max Column Sum

max_col_sum

Problem 3 - Print Square Matrix Diagonals

square_matrix_diag

Problem 4 - Print all Diagonals from Right -> Left

Problem Understanding all_diag_r_l_statement Observation all_diag_r_l_conditions Solution all_diag_r_l_solun

Transpose Matrix

matrix_transpose

Rotate Matrix

rotate_matrix

Refer:

2D Matrix

Rotate Matrix

Spiral Array