hey..need some help with a magic square assignment that takes odd integers as per the user input for the array setup..i still dont know about pointers so cant use that and i have not been able to come up with much except the basic below. im lost. how do i go about this??
thnx
CODE
int main()
{
int n;
cout<<"Enter the integer value for your magic square"<<endl;
cin>>n;
int matrix[n][n];
fillmatrix(matrix, n);
printmatrix(matrix, n);
return 0;
}
void fillmatrix(int matrix[][n], int size)
{
for(int row = 0; row < size; row++)
{
for(int col = 0; col = n; col /2)
{
matrix[row][col] = 1;
}
}
}
these were my instructions:
Place 1 in the middle column of the top row.
Then after integer k has been placed, move up one row and one column to the right to place the next integer k + 1, unless one of the following occurs:
If a move takes you above the top row in the ith column, move to the bottom of the ith column and place k + 1 there
If a move takes you outside to the right of the square in the ith row, place k + 1 in the ith row at the left side.
If a move takes you to an already filled square or if you move out of the square at the upper right-hand corner, place k + 1 immediately below k.
Write a program to construct n x n magic square for any odd value of n.
This post has been edited by john_231: 26 Sep, 2008 - 03:52 PM