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
*/