Program to Interchange Diagonals of Matrix | C # program to interchange the diagonals of matrix ; Function to interchange diagonals ; swap elements of diagonal ; Driver Code
using System ; class GFG { public static int N = 3 ; static void interchangeDiagonals ( int [ , ] array ) { for ( int i = 0 ; i < N ; ++ i ) if ( i != N / 2 ) { int temp = array [ i , i ] ; array [ i , i ] = array [ i , N - i - 1 ] ; array [ i , N - i - 1 ] = temp ; } for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) Console . Write ( array [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] array = { { 4 , 5 , 6 } , { 1 , 2 , 3 } , { 7 , 8 , 9 } } ; interchangeDiagonals ( array ) ; } }