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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int main ( ) { int matrix [ 5 ] [ 5 ] , 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 ; } } cout << " The ▁ matrix ▁ is STRNEWLINE " ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { cout << matrix [ row_index ] [ column_index ] << " ▁ " ; } cout << endl ; } cout << " Elements on Secondary diagonal : " 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 ) cout << matrix [ row_index ] [ column_index ] << " , ▁ " ; } } return 0 ; }