Skip to content

Instantly share code, notes, and snippets.

@javier-lopez
Created March 2, 2011 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javier-lopez/850210 to your computer and use it in GitHub Desktop.
Save javier-lopez/850210 to your computer and use it in GitHub Desktop.
int moda_fun (float numeros[], int cantidad)
{
int i,j;
float tmp[cantidad], tmp_[cantidad], moda=0, *max;
for (i = 0; i < cantidad; i++)
{
tmp[i]=0; //se limpian las variables
tmp_[i]=0;
}
for (i = 0; i < cantidad+1; i++)
{//+1 necesario para probar con el ultimo digito
for (j = 0; j < cantidad; j++)
{
if (numeros[i]==numeros[j])
{
tmp[i]+=1;
tmp_[i]+=1;
}
}
}
max=ordenar(tmp_, cantidad);
moda=max[cantidad-1];
for (i = 0; i < cantidad; i++)
{
if(moda==tmp[i])
{
moda=numeros[i];
break;
}
}
return moda;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment