Question
In C Fifth:Matrix Squares(10 points) A magic square is an arrangement of the numbers from 1 to n2 in an (n x n) matrix, with
In C
Fifth:Matrix Squares(10 points) A magic square is an arrangement of the numbers from 1 to n2 in an (n x n) matrix, with each number occurring exactly once, and such that the sum of the entries of any row, any column, or any main diagonal is the same. File is given no user input is given
An example of a Magic Square is as such:
2 7 6
9 5 1
4 3 8
In this case, the sum of all entries in a given row, column or main diagonal is equal to 15.
Your program should accept a file as command line input. The format of a sample file file1.txt is shown below:
3 8 1
6 3 5
7 4 9 2
The first number (3) corresponds to the size of the square matrix (n). The dimensions of the matrix will be n x n. You can assume there will be no malformed input and the matrices will always contain valid integers. If the given matrix follows the rules for a magic square, your program should output magic. If the matrix thats given is valid, but does not follow rules for a Magic Square, your program should output not-magic
Example Execution: A sample execution with above input file file1.txt is shown below:
$./fifth file1.txt
magic
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started