Distance from the top would be row,
int row = (int)(13/5); // 2
Distance from the left would be column, take the remainder of 13 by 5.
int col = (int)(13%5); // 3
Distance from the right would be the column minus total columns (5)
int colFromRight = 5-col-1; // 1
Distance from the bottom would be the row minus total rows (5)
int rowFromBottom = 5-row-1; // 2
Edit:
Heres a little diagram th at may help
heres an 1 dimensional array that we want to treat as a 2d array. It has 2 rows and 3 columns for a total of 6 elements. In our program it is a 1d array like this, I am using brackets[] for looks not syntax.
[1][2][3][4][5][6]
visually it would be like this
[1][2][3]
[4][5][6]
So to get the row of say location 5 we say
int location = 5;
int row = floor(location/3);
As you can see every time the row becomes 1+ a multiple of 3 the row number will increase.
for columns its the same thing but with a remainder.
int location = 5;
int column = location%3;
Here every time the location reaches 3 the remainder returns to 0 and the columns start over (essential signaling a new row).