Question: Variables and Expressions & Working with math.h header file Objective The objective of this Programming Project is to write a C Program to find the
Variables and Expressions & Working with math.h header file
Objective
The objective of this Programming Project is to write a C Program to find the distance between two places on Earth by using the functions provided by the math header file.
Program Description
Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earths mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed:
-
- Program must have header comments stating the author of the Program, date, and Program Description.
- Include the math.h header file in addition to the other header files that may be needed. (You may refer to https://en.wikibooks.org/wiki/C_Programming/math.h for all the functions available in math.h header file.)
- Initialize a variable with the value of earths radius. (Take earths radius as 6371.01 km).
- Prompt the user to enter the Starting Latitude. Read that number into a user-defined variable. (Remember to convert the input to float. Also the input needs to be further converted to radians.) You may use value of PI as 3.141592654
- Step 4 has to be repeated for accepting the values of Starting Longitude, Ending Latitude, and Ending Longitude.
- Compute the distance between the two places using any one of the following formulas:
Spherical Law of Cosines:
distance =
R*acos(sin(start_lat)*sin(end_lat)+cos(start_lat)*cos(end_lat)*cos(start_long- end_long))
where R = Earths Radius
Haversine Formula:
R = earths radius difflat = end_lat start_lat difflong = end_long start_long a = sin(difflat/2) + cos(start_lat) * cos(end_lat) * sin(diflong/2) c = 2 * atan2(sqrt(a), sqrt(1-a)) d = R * c
-
- Display the distance between the two places as:
The distance between the two places is (calculated distance) kms.
Save your program as Project1.c
Rubric:
Comments: 5
Descriptive and meaningful variables: 5
Correct Header files included: 3
Proper User Prompts: 5
Conversion of degrees to radians: 5
Correct usage of constants pi and earth's radius: 4
Formula applied correctly: 5
Formatting output: 4
Program executes and tested with actual values: 9
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
