# Thread: Finding maximum value and its coresspoding number in 2d array

1. ## Finding maximum value and its coresspoding number in 2d array

I have 2 question regarding 2d array. I am whether my program i working in the way I am want or not. I have to make a program to store values in one column and numbers in second column. (Table is just an example not actual values and numbers).
 0.1 1 -0.7 2 0.2 5 0.5 3
Then call the number stored at maximum value (which is number 3 stored at Max value 0.5).
I have stored values and numbers in array as mentioned below. Although it is not showing me any error. Just want to double confirm whether it is a right way to do so? Second thing how can I call this array to find out the number stored at maximum value?

Code:
```    double n;
int val=0;
int numb=0;
static double MyValue = 0.0;
static double number = 0.0;
static double lastValue = 0.0;
static double
CalculateMyValue(Node* node, int a){ // a is taken as argument
float b =0.3;
int bd = CalculateNumber(node); //calling another program
......
.....

{
MyValue = ((1-a)*LastValue);  //MyValue = {0.1,-0.7..}
{
number = bd;              //number = {1,2,..}
numb++;
}
n[val][numb] = number;
cout<<"Number = n[val][numb]  =  "<<n[val][numb]<<endl;
val++;
n[val][numb] = MyValue;
cout<<"MyValue =  n[val][numb] =  "<<n[val][numb]<<endl;
LastValue = MyValue;
}
return MyValue;
}

Here I want to call this array to find out the number stored at maximum value

void CalculateNumber(Node* node)
{
..............
..............
else {
Mymuber = ???     //number stored at maximum value in array
}
}``` 2. You need to be aware that, for historical reasons, 2D arrays in C and C++ are quite complex things that don't work well and simply, as in most programming languages. There's also an unfortunate tendency to introduce them in chapter two or three of "C++ Programming 101" because 1D arrays are basic, and 2D arrays look at first sight like a natural extension.

To get the maximum element, check the array for empty or null (width or height zero) and do something appropriate e.g. return Nan.
Set maximum to element 0, 0. Iterate over the rows and columns, and if you find a higher element, set maximum to that.

very simple. The issue is the array representation. The route many experienced programmers use is to simply set up a 1d array
of width * height elements in memory and access by array[y*width+x]. Then it integrates with low level code, and all Popular pages Recent additions c progamming, c program arrays, c++, number, visual c++ 2008 