Thread: Array Diagonals Reversion?

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    13

    Question Array Diagonals Reversion?

    Challenging us on the last day of class with the ultimate question, my professor gave us this problem.
    It's nearing midnight (11:55), and I've completely given up hope.

    This is the problem:

    Reverse the diagonals of a square 2-D array for any size square array.

    For example,
    9 8 7
    6 5 4
    3 2 1

    would become:

    1 8 3
    6 5 4
    7 2 9

    Likewise, the array

    1 2 3 4

    5 6 7 8

    9 10 11 12

    13 14 15 16


    would become:
    12 2 3 14

    5 11 10 8

    9 7 16 12

    4 14 15 1

    Exactly what sort of C++ wonder would I have to use to solve this problem?
    Just any hint would be helpful and much appreciated (:
    Last edited by ieatcalculus; 07-28-2010 at 09:59 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    13
    I have no idea how to even start. It's past midnight now

    I just need a hint; I obviously have to write the program myself.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I would imagine that you have to use a loop or two to swap diagonal entries.

    You can start with a simpler problem: print the diagonal entries of a square array of arbitrary order.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multidimensional Array Addressing
    By BlackOps in forum C Programming
    Replies: 11
    Last Post: 07-21-2009, 09:26 PM
  2. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM