Answer:
//Program in C.
// header file
#include <stdio.h>
#include <math.h>
// main function
int main(void) {
// variables
float x1,y1,x2,y2;
float s,xm,ym,d;
// ask to enter x coordinate of A
printf("Enter coordinate (x) of point A:");
// read x1
scanf("%f",&x1);
// ask to enter y coordinate of A
printf("Enter coordinate (y) of point A:");
// read y1
scanf("%f",&y1);
// ask to enter x coordinate of B
printf("Enter coordinate (x) of point B:");
//read x2
scanf("%f",&x2);
// ask to enter y coordinate of B
printf("Enter coordinate (y) of point B:");
// read y2
scanf("%f",&y2);
// calculate Midpoint of A and B
xm=(x1+x2)/2;
ym=(y1+y2)/2;
// calculate slope of the line
s=(y2-y1)/(x2-x1);
// calculate Distance between two points
d=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
// print result
printf("Midpoint of both the point is: %f %f",xm,ym);
printf("\nSlope of both the line is: %f",s);
printf("\nDistance between both the point is: %f",d);
return 0;
}
Explanation:
Read the x & y coordinates of both the points.Then calculate the Midpoint of both the and assign it to variables "xm"&"ym".Then calculate the slope of the line and assign it to variable "s".Then find the distance between the two points and assign it to variable "d".Print all these results.
Output:
Enter coordinate (x) of point A:2
Enter coordinate (y) of point A:3
Enter coordinate (x) of point B:9
Enter coordinate (y) of point B:8
Midpoint of both the point is: 5.500000 5.500000
Slope of both the line is: 0.714286
Distance between both the point is: 8.602325