Row and column index
If i have current index and row/columns count how do i get on which row and on which column index is individually?
This is what i have tried, but column index is incorrect:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
int main()
{
int rows = 5;
int colm = 6;
int inx = 12;
int rowInx = inx % rows;
int colInx = inx % colm;
std::cout << "row: " << rowInx << std::endl;
std::cout << "col: " << colInx << std::endl;
return 0;
}
|
Is this it?
1 2
|
int rowInx = inx / colm;
int colInx = inx % colm;
|
12 mod 5 is 2
12 mod 6 is 0
both indices are wrong
Thanks.
Topic archived. No new replies allowed.