The statement
p=row+col+1;
is your cause of trouble. You are trying to squeeze a two-dimensional position into a single int value. That's possible, but in that case the mapping should be unique. With your mapping method position (1,2) and (2,1) would both be mapped to the same value of p.
Try the following instead:
p = row * W + col;
W is the number of elements per row, in your case 3. Now every element of your array will produce a distinct p value.
Besides, the +1 in your method was probably just a way of numbering elements starting with 1 instead of 0. That might be a good idea for human output, but not if you are using the value of p in your program. Zero-based index values are a lot more convenient, particularly when you know that
all your index values in a program are zero-based. In other words: Don't mix zero- and one-based.
As an alternative, you can store the position in two separate int variables, for example:
int xMax = -1;
int yMax = -1;
if (a[row][col] > max)
{
max = a[row][col];
xMax = col;
yMax = row;
}
Hope that helps.