Sai_Bot

UNICAMP1

Nov 25th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. int* consulta_cidades_por_raio(Cidade* cidades, int cidadeReferencia, float raio, int n, int* nRetorno) {
  2.     int i, j = 0;
  3.     int *indicesCidades;
  4.    
  5.     for( i=0; i<n; i++){
  6.         if(distancia(cidades[cidadeReferencia].coordenadas, cidades[i].coordenadas)<= raio){
  7.             (*nRetorno)++;
  8.         }
  9.     }
  10.    
  11.     indicesCidades = malloc((*nRetorno) * sizeof(int));
  12.    
  13.     for( i=0; i<n; i++){
  14.         if(distancia(cidades[cidadeReferencia].coordenadas, cidades[i].coordenadas)<= raio){
  15.             indicesCidades[j] = i;
  16.             j++;
  17.         }
  18.     }
  19.    
  20.     return *indicesCidades;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment