1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
   | #include "test.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int stationProche(Point pt,Stations *station)
{    
  int i;     
  double distancebest=999999;
  long stationbest=0;
  double res=0;
 
  for(i=0;i<=5;i++)
  {
    res = sqrt(((pt.x-station[i].x)*(pt.x-station[i].x))+((pt.y-station[i].y)*(pt.y-station[i].y)));
    if(res < distancebest)
    {
      distancebest=res;
      stationbest = station[i].num;
    }
 
    return stationbest;
 
  }
  return 1;
}        
 
 
int main(int argc, char *argv[])
{
    Point pt;
    pt.x = 371;
    pt.y = 46;
    //pt.nom = "LaMottePicquet";
 
 
    Stations station[21];
    //station[0].nom = "Abesses";
    station[0].num = 0;
    station[0].position = 0;
    station[0].x = 308;
    station[0].y = 536;
    //station[1].nom = "AlexandreDumas";
    station[1].num = 1;
    station[1].position = 1;
    station[1].x = 472;
    station[1].y = 386;
    //station[2].nom = "AlmaMarceau";
    station[2].num = 2;
    station[2].position = 2;
    station[2].x = 193;
    station[2].y = 404;
    //station[3].nom = "Alesia";
    station[3].num = 3;
    station[3].position = 3;
    station[3].x = 290;
    station[3].y = 244;
    //station[4].nom = "AnatoleFrance";
    station[4].num = 4;
    station[4].position = 4;
    station[4].x = 138;
    station[4].y = 517;
    //station[5].nom = "Anvers";
    station[5].num = 5;
    station[5].position = 5;
    station[5].x = 324;
    station[5].y = 521;
 
    printf("la station la plus proche est la : %ld",stationProche(pt,station));
 
    system("PAUSE");
	return 1;
} | 
Partager