Array Diagonals Reversion?

This is a discussion on Array Diagonals Reversion? within the C++ Programming forums, part of the General Programming Boards category; Challenging us on the last day of class with the ultimate question, my professor gave us this problem. It's nearing ...

  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 10:59 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    22,304
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 10:26 PM
  2. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

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