88.4k views
5 votes
3. Write a program that asks the user to type the coordinate

of 2 points, A and B (in a plane), and then writes the
distance between A and B.

User Zambezi
by
6.0k points

1 Answer

5 votes

Answer:

#include <stdio.h>

#include <math.h>

int main()

{

float x1, y1, x2, y2, gdistance;

printf("Input x1: ");

scanf("%f", &x1);

printf("Input y1: ");

scanf("%f", &y1);

printf("Input x2: ");

scanf("%f", &x2);

printf("Input y2: ");

scanf("%f", &y2);

gdistance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));

printf("Distance between the said points: %.4f", sqrt(gdistance));

printf("\\");

return 0;

}

Here we need two coordinates so we need 4 variables namely x1, y1, x2, y2 to obtain the input from the user and to calculate distance we need another variable. So finally the result should be printed.

User Janak
by
5.7k points