Help with array max position


hi everyone,
i have question please

if have array of 12 variables , found max code
how can fine position of max variable in array ?

for example if value of v5 max, code show position v5 (which position 4 in array) holds max variable ?

and thank you

example code:

code: [select]

float v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12;
float v[12] = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };

float v_max = maximum(v,12);



float maximum(float *data,int count)
{
 int l;
 float maxval;
 maxval = 1.175494351e-38f;
 for(l=0; l<=count; l++)
 {
   if(data[l] > maxval)
   {
     maxval = data[l];
   }
 }
 return maxval;
}

in same way saving maximum value variable remember it, save loop index variable give index max number.


Arduino Forum > Using Arduino > Programming Questions > Help with array max position


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code