How to access elements of a Square Matrix | C # 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
using System ; class GFG { public static void Main ( String [ ] args ) { int [ , ] matrix = new int [ 5 , 5 ] ; int 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 ; } } Console . Write ( " The ▁ matrix ▁ is STRNEWLINE " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { Console . Write ( " { 0 } TABSYMBOL " , matrix [ row_index , column_index ] ) ; } Console . Write ( " STRNEWLINE " ) ; } Console . Write ( " on Secondary : " for ( row_index = 0 ; < size ; ++ ) { for ( column_index = 0 ; < size ; ++ ) { if ( ( row_index + column_index ) == size - 1 ) Console . Write ( " { 0 } , ▁ " , matrix [ row_index , column_index ] ) ; } } } }