PLEASE DO NOT use ChatGPT or any other AI-generated sources. T_T I am looking for a NEW code! The inputs are text files. Output doesn't
PLEASE DO NOT use ChatGPT or any other AI-generated sources. T_T
I am looking for a NEW code! The inputs are text files. Output doesn't have to be a text file.
It's C programming :) It will be great to have some explanation! Thank you!
Part 2: Magic square In this part, you write a program using recursion to solve the magic square game. You may check the Wikipedia page (https://en.wikipedia.org/wiki/Magic square) to read about what a magic square is. Basically, a magic square is an n X ngrid in which each cell is filled with a unique integer from 1 to 712, and each row, each column and each ofthe two main diagonals have the same sum ln(1 + 712). A magic square game is a partially completed n X 71 grid, and the 2 solver is to complete it to become a magic square, or claims Invalid when there is no solution. The main tasks of this part are two functions to be completed. The function int check( int n, int grid[n] [n]) checks whether the current n X n grid is a magic square, and returns 1 if it is a magic square or otherwise 0 . The other function int magic(int n, int grid[n] [11]) is a recursive function. When the current n X n grid is completed, it will check whether the grid is a magic square; otherwise, it will attempt to fill an empty cell with a legitimate integer' Your magic function should fill the magic square if possible and return 1, Otherwise, return 0 from the magic function to indicate it was not possible to make a magic square; Complete these two functions check and magic in the ex5q2.c file (see below) provided in the lab05.tar file: /* Purpose: Solving magic square * Author: * Date: * References: */ #include \"lab05.h" // Do not touch anything in this main function (used for testing purposes) int main() { return test_magic(magiC); // This line runs a compiled function in lab05b.o // This function is a nonrecursive function that checks whether a given grid[n][n] is a magic square. // Complete the function definition: int checklint n, int grid[n][n]) { // This function is a recursive function that intends to solve a given grid[n][n] as in the labOS description. // Complete the function definition: int magiclint n, int grid[n][n]) { An example run of the program is below. Be sure to match it exactly (for this particular input, the solution is unique): Example input file 1: 0 7 6 0 0 0 4 O 0 Example output 1: 2 7 6 9 5 l 4 3 8 Example input file 2 (wrong since there is more than one 1, among other things): 6 20 0 ll 0 l l 0 iibtoob HOMKI Example output 2: Invalid Use gcc Wall -std=c99 ex5q2.c lab05b.o [o ex5q2] to compile and your program's executable. [1 are the unix shell convention to indicate something is optional. In this case it means you can optionally add 0 ex5q2 to name your executable ex5q2 , otherwise it'll be named a.out as always. The labOSb.o object file will read in properly formatted files and print out properly formatted output. Your task is to make sure the check and magic functions are filled in correctly. Name your file ex5q2.c and add it to your submit.tar file
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