Find a Square Matrix such that sum of elements in every row and column is K | Function to print the required matrix ; Print k for the left diagonal elements ; Print 0 for the rest ; Driver code
def printMatrix ( n , k ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT print ( k , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "0" , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT print ( ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 ; k = 7 ; NEW_LINE printMatrix ( n , k ) ; NEW_LINE DEDENT