### 2d array call in function reading 1d array

Hi all,

I have the following code:

 ``1234567891011121314151617181920212223242526272829`` `````` int array[4][12] = { {1,0,0,0,0,0,0,0,0,0,0,0}, {1,0,0,1,0,0,0,0,0,0,0,0}, {1,0,0,0,0,0,0,0,1,0,0,0}, {1,0,0,0,0,0,1,0,0,0,0,0}}; int main() { Calculate(); Sort(); } void Calculate() { for(i = 0; i < 4; i++) { for(j = 0; j < 12; j++) { result[i] = Solve(array[i][j]); } } void Sort() { //Here I sort the values of result and based on this, I also sort the arrays (that is, I exchange the arrays with each other) } int Solve(int x[]) { //This function returns an int value by using the array x which has 1 dimension but actually this array is 2D as I defined at the beginning (array[4][12]). }``````

So, how can I use my 2d array in this 1d function? Thanks
Formula:
row * column size + column

So using your array array[4][12]

array[2][6] would be the same as array[2*12+6]
 ``1234567`` ``````void Calculate() { for (int i = 0; i < 4; i++) { result[i] = Solve(array[i]); } }``````
Topic archived. No new replies allowed.