/* Great Circle Distance Because the Earth is a sphere, the shortest distance between two points on the Earth's surface is not a straight line as you would draw on a map, but rather an arc. This arc is called the great circle route. This is why flights from Los Angeles to London will fly over Greenland and not the Eastern US. The great circle distance between two locations is given by this formula: d = R*acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2)*cos(lon2 - lon1)) Where: * d is the great circle distance between the 2 locations * lat1 and lat2 are the latitudes of locations 1 and 2, respectively * lon1 and lon2 are the longitudes of locations 1 and 2, respectively * R is the radius of the Earth (use 6371 km) * sin, cos, and acos are the sine, cosine, and arccosine functions, respectively You must write a complete C program that reads in the latitudes and longitudes of the two locations (in degrees) and outputs the great circle distance (in km) on the screen. All of the relevant mathematical functions can be found in math.h. Latitude is positive for North and negative for South, and Longitude is positive for East and negative for West. Print the result to 2 decimal places, i.e. %.2f in printf. =========SAMPLE RUN========= Enter the coordinates of location 1 (lat lon): -23.5 -46.62 Enter the coordinates of location 2 (lat lon): 41.9 12.5 The great circle distance between the locations is 9471.56 km. =====END OF SAMPLE RUN====== */ #include #include #include #define RADIUS_EARTH 6371 #define RAD_PER_DEGREE M_PI/180.0 int main(){ double lat1, lon1, lat2, lon2; //INPUTS double d; //OUTPUT //Read in the coordinates printf("Enter the coordinates of location 1 (lat lon): "); scanf("%lf %lf", &lat1, &lon1); printf("Enter the coordinates of location 2 (lat lon): "); scanf("%lf %lf", &lat2, &lon2); //Convert degrees to radians lat1 *= RAD_PER_DEGREE; lon1 *= RAD_PER_DEGREE; lat2 *= RAD_PER_DEGREE; lon2 *= RAD_PER_DEGREE; //Calculate the great circle distance d = RADIUS_EARTH * acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2)*cos(lon2-lon1)); //Print the result printf("\nThe great circle distance between the locations is %.2f km.\n", d); system("pause"); return 0; }