A magic square is a square matrix of size n*n where n is an odd integer value, and that each of the integers 1,2,3,... n^2 (that is n squared) appears exactly once. The sum of each column and that of each row as well that of the diagonal must be equal. For example, given a 5*5 magic square, the sum of each row, each column and each diagonal must be equal to 65 and 175 for a 7*7 magic square. Write a program that can be used to accept any odd number as matrix size and output the corresponding magic square.
Comments
Leave a comment