Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This will also involve the use of functions from the math library. This means th

ID: 3664495 • Letter: T

Question

This will also involve the use of functions from the math library. This means that you will need ttinclude at the top of your program, in addition to the minclude stdio.h> that you have been using. It also means that you will need to compile with the Hm option. IThat's an "er not a one. it means "load math. e.g. gcc -lm hw3.c The problem is this: You know that the formula for the distance between two points in a Cartesian plane is distance x2) (yi -y2) Your program should ask the user for the coordinates of their two points. The program should then calculate and display the distance between those points, nicely formatted with three decimal places.

Explanation / Answer

#include<stdio.h>
#include<math.h>
int main(){
  
    double x1,x2,y1,y2,d;     //declare the variables
    printf("Enter the x1 coordinate : ");      // ask the use to enter the value of x1
    scanf("%lf",&x1);                               //store the entered value in x1
     printf("Enter the x2 coordinate : ");      //ask the use to enter the value of x2
    scanf("%lf",&x2);                                 //store the entered value in x2
     printf("Enter the y1 coordinate : ");    // ask the use to enter the value of y1
    scanf("%lf",&y1);                                //store the entered value in y 1
     printf("Enter the y2 coordinate : ");     // ask the use to enter the value of y2
    scanf("%lf",&y2);                           //store the entered value in y2
  
    d=sqrt((pow(x1-x2,2))+(pow(y1-y2,2)));    //calculate the distance using the given formula
    printf("Distance between the coordinates = %.3lf",d);    //display the distance calculated with three decimal places
   
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote