(please run your program before submitted) It is absolutely crucial to end all o
ID: 3628603 • Letter: #
Question
(please run your program before submitted)
It is absolutely crucial to end all of your programs with:
return 0;
as the last line before the closing '}' bracket in your main function.
Programs that do not follow this convention will not be graded correctly.
Programs that end with that line may still fail because they do not
generate the right output.
Each sample run is indicated by a line of "=" symbols. These lines only indicate
the start and the end of a sample run and should not be printed by
your program.
Use 64-bit floating point numbers (i.e., double) for all floating
point calculations. Do not use float as your results may differ from the test cases
due to small precision errors.
(ADD system ("pause"); and retunr 0; at the end)
Problem 1
#########
Write a complete C program that prompts the user for the coordinates
of two 3-D points (x1, y1, z1) and (x2, y2, z2) and displays the
distance between them computed using the following formula:
distance = sqrt((x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2)
Remarks: Please replicate the exact text of the prompts and the
output. Make sure that the roots are printed with two digit precision
(i.e., "%.2f" in printf). Even though the text must be the same, the
numbers may be different depending on the user input.
============= START OF SAMPLE RUN =======================
Please enter the coordinates of the first point:
x1 = 0.123
y1 = 0.456
z1 = 0.789
Please enter the coordinates of the second point:
x2 = 0.987
y2 = 0.654
z2 = 0.321
The distance between the two points is 1.00
============= END OF SAMPLE RUN =======================
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
double a,b,c;
double x,y,z;
double dist;
printf(" ============= START OF SAMPLE RUN ======================= ");
printf("Please enter the coordinates of the first point: ");
scanf("%lf %lf %lf",&a,&b,&c);
printf("Please enter the coordinates of the second point: " );
scanf("%lf %lf %lf",&x,&y,&z);
dist = sqrt(pow((a - x),2) + pow((b - y),2) + pow((c - z),2));
printf("The distance between the two points is %.2lf ", dist);
printf(" ============= END OF SAMPLE RUN ======================= ");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.