This C program checks if a given square matrix is a βMagic Squareβ. A Magic Square is a square grid filled with distinct integers such that the sum of numbers in each row, column, and both main diagonals is the same.
This program was created as part of the Systems Programming 20465 course in the 2022a semester at The Open University of Israel and achieved a perfect score. ππ
3x3 Magic Square:
3x3 Non-Magic Square:
5*5 Magic Square:
invalid input:
too many inputs:
is_valid_char
: Checks if a character is a valid digit or whitespace.get_char_and_skip_spaces
: Reads characters, skipping whitespaces.get_num
: Converts character digits to an integer.is_square
: Verifies if the correct number of inputs is provided.print_mat
: Prints the matrix.check_diagonal
, check_row_col
, is_magic
: Functions to check if the matrix is a magic square.print_mat_with_index
: Displays the matrix with indexes.free_mat
: Frees allocated memory.new_square
: Main function to create and test the square.Feel free to fork the repo and submit pull requests for improvements!
This project is open source and available under the MIT License.
Enjoy checking your magic squares! π©β¨