- #include<stdio.h>
- #include<math.h>
- #define PI 3.1415926
- #define R 6371.137
- #define RAD PI/180.0
- int main()
- {
- float a1,b1,a2,b2;
- float x1,y1,A1,B1;
- float s;
- printf("please input first longitude and latitude\n");
- scanf("%f%f",&a1,&b1);
- printf("plsease input second logitude and latitude\n");
- scanf("%f%f",&a2,&b2);
- A1=b1 * RAD;
- B1=b2 * RAD;
- x1 = A1 - B1;
- y1 = (a1-a2)*RAD;
- s=2*asin(sqrt(pow(sin(x1/2),2) +
- cos(b1)*cos(b2)*pow(sin(y1/2),2)));
- s *= R;
- printf("The distance is %f\n",s);
- }