Specification Write a program which creates an odd sizedmagic square by using th
ID: 3619159 • Letter: S
Question
Specification
Write a program which creates an odd sizedmagic square by using the Siamese method,
and prints out the magic square each time anew cell of the square is filled out. A magic
square of size N is a square arrangement ofthe numbers 1, 2, ... N2 so that therows,
columns and diagonals all add up to the samenumber. The size of the magic square will
be specified by the user.
To constrain the size of the square, as wellas the length of numbers within the square,
the program will only allow sizes which areless than 100. In addition, the Siamese
method only works for odd sized magicsquares. The program must check that the size
entered by the user is positive, that it isan odd number and also that it is less than 100.
If the user enters a number which isnegative, even, or greater than or equal to 100,than
the program will print the proper errormessage and prompt for the size again. Notice
that the program does not terminate as wasthe case in the previous assignment. For
this assignment, it will continuously printerror messages and reprompt for the size until
an odd number between 0 and 100 isentered.
After an odd number between 0 and 100 isentered, the program will then fill out the
magic square using the Siamesemethod(described below), printing out the currentstate
of the magic square each time a new cell isfilled out.
Siamesemethod
1. Start by placing the number 1 in themiddle column of the top row
2.Place each of the remaining numbers (2, 3, ...N2) by moving up one row andright
one column. Any attempt to go outside thebounds of the array should “wrap
around” to the opposite side of thearray. So if going up goes out of the table,
move to the bottom row. If going right goesout of the table, the go to the leftmost
column.
3. If a particular cell of the square isalready occupied, then place the next number in
the cell below the previously filled outcell.
Explanation / Answer
please rate - thanks #include #include void print(int[][100],int); int main() {int i,j,n,filled=0,row=0,col=0,num=1,spaces; int prevrow,prevcol; int ms[100][100]={0}; printf("How large is your square: "); scanf("%d",&n); while(n100) {printf("size must be positive, odd,Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.