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