#include #include "geography.h" /** * Computes the distance of a path given the latitudes and longitudes * of the points on the path. The coordinates are read from standard input * and assumed to be in degrees. The output is the number of points in the * path and the total distance using the great circle distance between adjacent * points. * * Compile and link with * gcc -Wall -std=c99 -pedantic distance.c * gcc -Wall -std=c99 -pedantic more_math.c * gcc -Wall -std=c99 -pedantic geography.c * gcc -o Distance distance.o more_math.o geography.o -lm * * @version 0.2 2018-09-06 colatitude now works in radians * @version 0.1 2017-09-01 */ int main() { double total_distance = 0.0; double prev_lat, prev_lon; double curr_lat, curr_lon; // upgraded to read user input (no more hard-coding) and calculate // the distance along a multi-point route (using a loop!) int n = 0; while (scanf("%lf %lf", &curr_lat, &curr_lon) == 2) { n++; if (n >= 2) { total_distance += distance(prev_lat, prev_lon, curr_lat, curr_lon); } prev_lat = curr_lat; prev_lon = curr_lon; } printf("%d points; total distance %lf miles\n", n, total_distance); }