luc006.c (947B)
1 /* Write a program to receive values of latitude (L1, L2) and longitude 2 (G1, G2), in degrees, of two places on the earth and output the distance 3 (D) between them in nautical miles. The formula for distance in nautical 4 miles is : 5 D = 3963 cos^-1(sin L1 sin L2 + cos L1 cos L2 * cos(G2 - G1)) 6 */ 7 /* Let Us C, Chap - 2, Page - 37, Qn no.: G(c) */ 8 9 #include <stdio.h> 10 #include <math.h> 11 int main() 12 { 13 double l1, l2, g1, g2, d; 14 printf("Enter the Latitude in 'L1, L2' format : "); 15 scanf("%lf, %lf", &l1, &l2); 16 printf("Enter the Longitude in 'G1, G2' format : "); 17 scanf("%lf, %lf", &g1, &g2); 18 // Converting degree to radian because function from math.h use radian not degree 19 l1 = l1 * (M_PI / 180); 20 l2 = l2 * (M_PI / 180); 21 g1 = g1 * (M_PI / 180); 22 g2 = g2 * (M_PI / 180); 23 d = 3963 * acos(sin(l1) * sin(l2) + cos(l1) * cos(l2) * cos(g2 - g1)); 24 printf("Distance in nautical miles : %g", d); 25 return 0; 26 }