Demo entry 6881478

Assignment1.c

   

Submitted by anonymous on Sep 11, 2019 at 04:05
Language: C. Code size: 992 Bytes.

#include<stdio.h>
#include<math.h>
#define PI acos(-1)
#define R 6371
char first_name[50],second_name[50];
int main()
{
	double first_latitude,second_latitude,first_longitude,second_longitude;
	printf("The first city:\nPlease input the city name: ");
	gets(first_name);
	printf("Please input the latitude: ");
	scanf("%lf",&first_latitude);
	printf("Please input the longitude: ");
	scanf("%lf",&first_longitude);
	printf("The second city:\nPlease input the city name: ");
	gets(second_name);
	printf("Please input the latitude: ");
	scanf("%lf",&second_latitude);
	printf("Please input the longitude: ");
	scanf("%lf",&second_longitude);
	double phi1=(90-first_latitude)/180*PI,phi2=(90-second_latitude)/180*PI;
	double theta1=first_longitude/180*PI,theta2=second_longitude/180*PI;
	double c=sin(phi1)*sin(phi2)*cos(theta1-theta2)+cos(phi1)*cos(phi2);
	double d=acos(c)*R;
	printf("The distance between %s and %s is %.2lf km",first_name,second_name,d);
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).