Q: 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.
#include <stdio.h>
#include <math.h>
int main()
{
float D,L1,L2,G1,G2;
printf("enter the value of L1,L2,G1 and G2 in digree :\n");
scanf("%f%f%f%f",&L1,&L2,&G1,&G2);
/*formula used to find distance between two points on earth in nautical miles*/
D=3963*(acos(sin(L1*3.14/180)*sin(L2*3.14/180)+cos(L1*3.14/180)*cos(L2*3.14/180)*cos(G2*3.14/180-G1*3.14/180)))*180/3.14;
printf("\ndistance is %f",D);
return 0;
}
-----------------------------------------
output :
enter the value of L1,L2,G1 and G2 in digree :
3
4
5
6
distance is 5599.273438
#include <math.h>
int main()
{
float D,L1,L2,G1,G2;
printf("enter the value of L1,L2,G1 and G2 in digree :\n");
scanf("%f%f%f%f",&L1,&L2,&G1,&G2);
/*formula used to find distance between two points on earth in nautical miles*/
D=3963*(acos(sin(L1*3.14/180)*sin(L2*3.14/180)+cos(L1*3.14/180)*cos(L2*3.14/180)*cos(G2*3.14/180-G1*3.14/180)))*180/3.14;
printf("\ndistance is %f",D);
return 0;
}
-----------------------------------------
output :
enter the value of L1,L2,G1 and G2 in digree :
3
4
5
6
distance is 5599.273438
Comments
Post a Comment