Sai_Bot

new

Nov 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1.  
  2. float mediana_da_populacao(Cidade* cidades, int cidadeReferencia, float raio, int n) {
  3.     int *vet, j=0, i, k, temp, aux;
  4.     float mediana;
  5.    
  6.     for (i=0; i<n; i++){
  7.         if(distancia(cidades[cidadeReferencia].coordenadas, cidades[i].coordenadas)<= raio){
  8.             j = j + 1;
  9.             vet = malloc(j * sizeof(int));
  10.             vet[j-1]= cidades[i].numHabitantes;
  11.  
  12.         }
  13.     }
  14.    
  15.     for(i = 0; i < i-1; i++){
  16.         temp = vet[i];
  17.         for(k = 0; k < j; k++){
  18.             if(temp > vet[k]){
  19.                 aux = vet[k];
  20.                 vet[k] = vet[k];
  21.                 vet[k] = aux;
  22.             }
  23.         }
  24.     }
  25.    
  26.     if (j%2 == 0){
  27.      mediana = vet[(j+1)/2];
  28.        
  29.     }else{
  30.         mediana = (vet[j/2] + vet[(j/2)+1])/2;
  31.  
  32.     }
  33.     return mediana;
  34. }
Add Comment
Please, Sign In to add comment