How to access elements of a Square Matrix | Javascript Program to read a square matrix and print the elements on secondary diagonal ; Get the square matrix ; Display the matrix ; Print the elements on secondary diagonal ; Check for elements on secondary diagonal
let matrix = new Array ( 5 ) ; for ( let i = 0 ; i < 5 ; i ++ ) { matrix [ i ] = new Array ( 5 ) ; for ( let j = 0 ; j < 5 ; j ++ ) { matrix [ i ] [ j ] = 0 ; } } let row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } document . write ( " " ) ; } document . write ( " " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) == size - 1 ) document . write ( matrix [ row_index ] [ column_index ] + " " ) ; } }