How to access elements of a Square Matrix | C ++ Program to read a square matrix and print the Corner Elements ; Get the square matrix ; Display the matrix ; Print the Corner elements ; check for corner elements
#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 " << endl ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { cout << " TABSYMBOL " << matrix [ row_index ] [ column_index ] ; } cout << endl ; } cout << " Corner Elements are : " ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index == 0 row_index == size - 1 ) && ( column_index == 0 column_index == size - 1 ) ) cout << matrix [ row_index ] [ column_index ] << " , " ; } } return 0 ; }