Cody

Problem 44450. Create a magic square matrix for a given odd integer

Solution 1490089

Submitted on 13 Apr 2018 by Binbin Qi
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
n = 3; y_correct = [15 15 15 15]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

varargout = 1×4 cell array {[15]} {[15]} {[15]} {[15]}

2   Pass
n = 5; y_correct = [65 65 65 65]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

varargout = 1×4 cell array {[65]} {[65]} {[65]} {[65]}

3   Pass
n = 9; y_correct = [369 369 369 369]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

varargout = 1×4 cell array {[369]} {[369]} {[369]} {[369]}

4   Pass
n = 15; y_correct = [1695 1695 1695 1695]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

varargout = 1×4 cell array {[1695]} {[1695]} {[1695]} {[1695]}

Suggested Problems

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!