Create matrix whose sum of diagonals in each sub matrix is even | Function to prN * N order matrix with all sub - matrix of even order is sum of its diagonal also even ; Even index ; Odd index ; Iterate two nested loop ; For even index the element should be consecutive odd ; For odd index the element should be consecutive even ; Given order of matrix ; Function call
def evenSubMatrix ( N ) : NEW_LINE INDENT even = 1 NEW_LINE odd = 2 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT if ( ( i + j ) % 2 == 0 ) : NEW_LINE INDENT print ( even , end = " ▁ " ) NEW_LINE even += 2 NEW_LINE DEDENT else : NEW_LINE INDENT print ( odd , end = " ▁ " ) NEW_LINE odd += 2 NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT DEDENT N = 4 NEW_LINE evenSubMatrix ( N ) NEW_LINE