C++ - Magic Square X2
Magic Square X2 is an implementation of the magic square arithmetic from Chinese mathematics. A C++ application and code is provided for learning purposes.
Basically magic square is close-to Sudoku, but not quite. You specify a number on how big the matrix will be and that will also determine what numbers go in diagonal, row, and column all add up to. The key catch is you can only use each number once. Here is an image below that shows an example of what a basic magic square looks like:
In the above picture the specified number is 3, so the matrix is a 3x3. So the number that corresponds to a 3x3 is 15. Hence each diagonal, row, and column all add up to 15.
This is a really old video of me explaining and showing a demo of the small console application created using CodeBlocks.
The code isn't well-written. I could have done a switch case statement in an infinite while loop for selecting the operations. Maybe I could have used a recursive function for iterating through the matrix instead of using nested for loops (I think). If you want to change it so it can also solve even numbers just change the one if statement for checking if the user input is odd. You can also remove that statement if you want to just do the magic square for all given numbers.
The code is relatively short!
That's all there is for this article. If you have any questions or comments go ahead and do so below or in the video.
Comments powered by CComment