magic array

This is a discussion on magic array within the C++ Programming forums, part of the General Programming Boards category; hi all... I am trying to write an array matrix that will pull in a number that defines the array ...

  1. #1
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35

    magic array

    hi all...
    I am trying to write an array matrix that will pull in a number that defines the array size of rows and cols (like #3 means 3 rows 3 cols)
    and then wrap numbers around the matrix so that the sum diag, across and down are all equal

    here is the #3 example:

    8 1 6
    3 5 7
    4 9 2

    the sum is 15.

    supposedly the number 1 needs to be in the middle row of col 1.
    and each successive int up one and over one.

    I have been provided with an external file of 6 numbers each that are to be used to make a searate matrix.

    I am totally lost.
    My first 2d array program was before this and i could pull in data from an external file print as a matrix and like this arr[1][2]...
    but i am completely at a loss as to where the other numbers
    in the array come from...
    the instructions are:
    write a program that prints a magic cube as well as it's magic sum for an odd integer s greater than 1 but less than 17.
    maybe the instuctions are vague or I am just stupid..I am not asking for anyone to do my homework- i am asking for help understanding WHAT to do...
    someone with experience out there MUST know what it's like to
    look at a question and get a big ? in their head???
    thanks a lot
    Michele

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    I do not know of a mathematical shortcut. My solution is to create, for example, a 4x4 array and change the elements in the first 3 rolls and first 3 columns until you get the correct sum for all rolls, columns, and diagonals.

    Kuphryn

  3. #3
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35

    algorythms

    really?
    i'll try...
    what would it be called?
    sorry, I am really green an feeling stupid
    Michele

  4. #4
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35

    Thumbs up wow

    wow...thank you!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  5. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 05:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21