0

i know there is probably a trick for this in C that i do not know, but i attempted to write my own function for finding the mode of an array of data (As large as 1500 doubles).

Heres my crack at it.

```
void mode (double * array, int numItems)
{
double array_saved_noMulti[numItems];
int array_count[numItems], i = 0, n = 0, count = 0, max_count = 0, index = 0, index_2 = 0;
for (i = 0, n = 0; i < numItems; i++)
{
if (array[i] != array[i+1])
{
array_saved_noMulti[n] = array[i];
n++;
}
}
for (i = 0, n = 0; n < numItems; n++)
{
while (array[i] == array[i + 1])
{
count++;
i++;
}
array_count[n] = count++;
n++;
count = 0;
}
array_count[0] = max_count;
for (i = 0; i < numItems; i ++)
{
if (array_count[i] > max_count)
{
array_count[i] = max_count;
index = i;
}
if (array_count[i] = max_count)
{
index_2 = i;
}
}
printf("The mode is %lf or %lf, which occurs %i times", array_saved_noMulti[index], array_saved_noMulti[index_2], max_count);
}
```

if there is an easier way to do this please enlighten, it would make my day.