Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,579 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,942 people online right now. Registration is fast and FREE... Join Now!




magic square

 
Reply to this topicStart new topic

magic square

john_231
26 Sep, 2008 - 03:51 PM
Post #1

New D.I.C Head
*

Joined: 26 Sep, 2008
Posts: 1

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
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 12:27AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month