Diagonal elements four dimensional array

Let's say you have a four dimensional array with two digit numbers:

12 22 34 45

33 01 02 05

04 98 21 13

03 21 45 11

I'm trying to list the diagonals in this script, but it's not working. The diagonals in this case are:

12, 1, 21, 11, 45, 2, 98, 3.

I don't have a debugger so I can't figure out what's wrong, but I have a feeling it's because of the if statement I wrote, primarily the row == column - 3, which technically defines the placement of 45, 02, 98 and 3 I believe. What is being done wrong here? (The array insertion is cut out from this.)

#include <iostream> //Older version of C++, not modern.
using namespace std;

for (int row = 0; row < 4; row++){
    for (int column = 0; column <= 4; column++){
        if (row == column || row==column-3){
            cout << array[row][column] << " ";
        }
    }
}

Answers


#include <iostream> //Older version of C++, not modern.
using namespace std;

for (int row = 0; row < 4; row++)
{
for (int column = 0; column <= 4; column++)
{
if (row == column || row == 3 - column)  // Not column - 3
{
    cout << array[row][column] << " ";
}
}
}

Need Your Help

Error when switching months on full calendar

jquery fullcalendar

I got a strange problem with fullcalendar. When I click on &lt; > buttons, the same ajax actions was executed moren than once, like the image on link: http://snag.gy/VQfEU.jpg

Sort NSArray by NSDate, today

iphone cocoa cocoa-touch core-data nsdate

I have loaded item from core data in an NSMutableArray. Each item, when created, is given a due date, that the user choices.