Monday, July 27, 2009

C++ Question with 2d arrays?

I need a function that takes in 2d array (any size) of ints, and prints it in diagonal slices, starting from the right-most slice. For example,





0 1 2 3


4 5 6 7


8 9 10 11





would print out as:


3


2 7


1 6 11


0 5 10


4 9


8





I know how to print a 2d array normally, and I know how to print the main diagonal, but thats about it. Any suggestions?





Thanks!

C++ Question with 2d arrays?
I would manipulate the arrays to be in reverse order, so you get:


3 2 1 0


7 6 5 4


11 10 9 8


Then if you print the diagonals (like you would know how to do) then you get the desired output.


If you need the array again, just manipulate it back before you do anything after the print.

id cards

No comments:

Post a Comment