Find a Square Matrix such that sum of elements in every row and column is K | C # implementation of the approach ; Function to print the required matrix ; Print k for the left diagonal elements ; Print 0 for the rest ; Driver code
using System ; class GFG { static void printMatrix ( int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) Console . Write ( k + " ▁ " ) ; else Console . Write ( "0 ▁ " ) ; } Console . Write ( " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int n = 3 , k = 7 ; printMatrix ( n , k ) ; } }