Write a program to receive values of latitude(L1, L2) and longitude(G1, G2), in degrees, of two places on the earth and output the distance (D) between them in nautical miles. The formula for distance in nautical miles is:
D = 3963 cos^-1( sin L1 sin L1 + cos L1 cos L1 * cos( G2- G1))
C Program : Solution
#include <stdio.h>
#include <math.h>
int main()
{
float L1,L2,G1,G2,distance,a;
const float PI = 3.14;
printf(“Enter the Latitude and Longitude of first place(L1,G1):”);
scanf(“%f%f”,&L1,&G1);
printf(“Enter the Latitude and Longitude of second place(L2,G2):”);
scanf(“%f%f”,&L2,&G2);
/* Conversion from degree to radians */
L1 = L1 * (PI/180);
L2 = L2 * (PI/180);
G1 = G1 * (PI/180);
G2 = G2 * (PI/180);
a = (sin(L1)*sin(L2)+cos(L1)*cos(L2)*cos(G1-G2));
distance = (3963 * acos(a));
printf(“The distance between the places is:%f”,distance);
return 0;
}
If you have any suggestions, kindly share with me.
