I want to find the value occurs most in an 8 integer array. Here is the code that I have. It does compile, but has not been tested.
Code:
int POLL (int *RANGE_ARRAY) {
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int j = 0;
int k;
int m = 0;
int n = 0;
int p;
for (k = 0; k < 8; k++) {
if (RANGE_ARRAY[0] == RANGE_ARRAY[k]) d++;
if (RANGE_ARRAY[1] == RANGE_ARRAY[k]) e++;
if (RANGE_ARRAY[2] == RANGE_ARRAY[k]) f++;
if (RANGE_ARRAY[3] == RANGE_ARRAY[k]) g++;
if (RANGE_ARRAY[4] == RANGE_ARRAY[k]) h++;
if (RANGE_ARRAY[5] == RANGE_ARRAY[k]) j++;
if (RANGE_ARRAY[6] == RANGE_ARRAY[k]) m++;
if (RANGE_ARRAY[7] == RANGE_ARRAY[k]) n++;
}
if (d >= (e & f & g & h & j & m & n)) p = 0;
if (e >= (d & f & g & h & j & m & n)) p = 1;
if (f >= (e & d & g & h & j & m & n)) p = 2;
if (g >= (e & f & d & h & j & m & n)) p = 3;
if (h >= (e & f & g & d & j & m & n)) p = 4;
if (j >= (e & f & g & h & d & m & n)) p = 5;
if (m >= (e & f & g & h & j & d & n)) p = 6;
if (n >= (e & f & g & h & j & m & d)) p = 7;
return (p);
}
Does this look right or is there a better way of doing this?