# Thread: two dimensional array help

1. ## two dimensional array help

Hi all hope someone can give me a few pointers.
This is what I want to achieve but don't understand.

I want to return the two dimentinal array position of the largest value in a sequence of numbers.

So here is my code so far which does not return the correct results.

Code:
```#include <stdio.h>		//preprocessor directive to include stdio
#define NUMROWS 3		//preprocessor defines
#define NUMCOLS 3

int main()			//ep to main
{

int i, j;			//for loop vars
int val[NUMROWS][NUMCOLS] = {1,2,3,4,5,6,7,8,9};
int maxnumpos = val[0][0];

for(i = 0; i < NUMROWS; i++)	//start outer loop
{
for(j = 0; j < NUMCOLS; j++)
if(val[i][j] > maxnumpos)
maxnumpos = val[i][j];
}

printf("the maximum value in the array is %d & is stored at postion %d %d\n", maxnumpos, val[i][j]);

}```
Can anyone give me some pointers to begin to understand how to deal with this scenario, whether it is code examples or a text to read

2. If you want to keep the position of the maximum value, you'll have to make a copy of where it is.
Code:
```#include <stdio.h>		//preprocessor directive to include stdio
#define NUMROWS 3		//preprocessor defines
#define NUMCOLS 3

int main()        //ep to main
{

int i, j;         //for loop vars
int val[NUMROWS][NUMCOLS] = {1,2,3,4,5,6,7,8,9};
int maxnumpos = val[0][0];
int maxi = 0, maxj = 0;

for ( i = 0; i < NUMROWS; i++ )  //start outer loop
{
for ( j = 0; j < NUMCOLS; j++ )
if ( val[i][j] > maxnumpos )
{
maxnumpos = val[i][j];
maxi = i;
maxj = j;
}
}

printf("the maximum value in the array is %d & is stored at postion %d %d\n",
maxnumpos, maxi, maxj);

}

/* my output
the maximum value in the array is 9 & is stored at postion 2 2
*/```

3. ## appreciation

many thanks I see it now.