To go the opposite direction which is what I needed:
void printxy(int index)
{
int y = (int)((-1+sqrt(8*index+1))/2);
int x = index - y*(y+1)/2;
}
More Related Contents:
- C++ – Find numbers between first and last negative numbers in Array
- Absolute Distinct Numbers
- What is the fastest way to transpose a matrix in C++?
- How to map the indexes of a matrix to a 1-dimensional array (C++)?
- How do you dynamically allocate a matrix?
- The intersection of two sorted arrays
- Searching in a sorted and rotated array
- Inverting a 4×4 matrix
- Print 2-D Array in clockwise expanding spiral from center
- Convert Eigen Matrix to C array
- What is the safe way to fill multidimensional array using std::fill?
- Insertion sort stops working after million input
- How do I compare chars (or strings) using void functions, also comparing chars that were taken from a struct array
- Is std::vector so much slower than plain arrays?
- Rotating a point about another point (2D)
- Create Random Number Sequence with No Repeats
- Vector of Vectors to create matrix
- How to initialize std::array elegantly if T is not default constructible?
- May I take the address of the one-past-the-end element of an array? [duplicate]
- How do I initialize a member array with an initializer_list?
- How do I best handle dynamic multi-dimensional arrays in C/C++?
- Structure of Arrays vs Array of Structures
- How to get the real and total length of char * (char array)?
- how to return numpy.array from boost::python?
- Most efficient/elegant way to clip a number?
- How do I store arrays in an STL list?
- C++ overloading array operator
- c++ expression must have a constant value
- Copying non null-terminated unsigned char array to std::string
- Generate N random numbers within a range with a constant sum