Interchange elements of first and last rows in matrix | C # code to swap the element of first and last row and display the result ; swapping of element between first and last rows ; Driver code ; input in the array ; printing the interchanged matrix
using System ; class GFG { public static void interchangeFirstLast ( int [ ] [ ] m ) { int rows = m . Length ; for ( int i = 0 ; i < m [ 0 ] . Length ; i ++ ) { int t = m [ 0 ] [ i ] ; m [ 0 ] [ i ] = m [ rows - 1 ] [ i ] ; m [ rows - 1 ] [ i ] = t ; } } public static void Main ( string [ ] args ) { int [ ] [ ] m = new int [ ] [ ] { new int [ ] { 8 , 9 , 7 , 6 } , new int [ ] { 4 , 7 , 6 , 5 } , new int [ ] { 3 , 2 , 1 , 8 } , new int [ ] { 9 , 9 , 7 , 7 } } ; interchangeFirstLast ( m ) ; for ( int i = 0 ; i < m . Length ; i ++ ) { for ( int j = 0 ; j < m [ 0 ] . Length ; j ++ ) { Console . Write ( m [ i ] [ j ] + " ▁ " ) ; } Console . WriteLine ( ) ; } } }