Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float mediana_da_populacao(Cidade* cidades, int cidadeReferencia, float raio, int n) {
- int *vet, j=0, i, k, temp, aux;
- float mediana;
- for (i=0; i<n; i++){
- if(distancia(cidades[cidadeReferencia].coordenadas, cidades[i].coordenadas)<= raio){
- j = j + 1;
- vet = malloc(j * sizeof(int));
- vet[j-1]= cidades[i].numHabitantes;
- }
- }
- for(i = 0; i < i-1; i++){
- temp = vet[i];
- for(k = 0; k < j; k++){
- if(temp > vet[k]){
- aux = vet[k];
- vet[k] = vet[k];
- vet[k] = aux;
- }
- }
- }
- if (j%2 == 0){
- mediana = vet[(j+1)/2];
- }else{
- mediana = (vet[j/2] + vet[(j/2)+1])/2;
- }
- return mediana;
- }
Add Comment
Please, Sign In to add comment