Skip to content

Instantly share code, notes, and snippets.

@SwampDragons
Forked from chrisgilmerproj/gist:1435738
Created December 5, 2011 23:46
Show Gist options
  • Save SwampDragons/1435956 to your computer and use it in GitHub Desktop.
Save SwampDragons/1435956 to your computer and use it in GitHub Desktop.
Simple mode code
void mode(float *s, int count)
{
int c_new=0;
int c_old=0;
float mode_new=0.0;
float mode_old=0.0;
float num;
int i;
for(i=0; i<count; i++)
{
num = s[i];
if (num!= mode_new)
{
if(c_new > c_old)
{
c_old = c_new;
mode_old = mode_new;
c_new =0;
}
mode_new = num;
}
c_new++;
}
printf("Mode: %f\n", mode_old);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment