Hello friends!!!!!
Implementing 2D point Geometry
#include<stdio.h>
#include<math.h>
//Initializing the structure point
struct point{
float x;
float y;
};
//Function to find and return the value of distance between two points
float distance(struct point p1, struct point p2){
float distance;
distance = (float) sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
return distance;
}
struct point mid_point(struct point p1, struct point p2){
struct point p3;
p3.x = (p1.x + p2.x )/2;
p3.y = (p1.y + p2.y)/2;
return p3;
}
//Function to find the slope of given two points
float slope(struct point p1, struct point p2){
float m;
m = (p1.y - p2.y) / (p1.x - p2.x);
return m;
}
int main (){
struct point p1,p2,p3;
printf("Enter x coordinate: ");
scanf("%f", &p1.x);
printf("Enter y coordinate: ");
scanf("%f", &p1.y);
printf("Enter x coordinate: ");
scanf("%f", &p2.x);
printf("Enter y coordinate: ");
scanf("%f", &p2.y);
printf("%.2f is distance\n", distance(p1,p2));
p3 = mid_point(p1,p2);
printf("(%.2f , %.2f) is midpoint\n", p3.x , p3.y);
float m = slope(p1,p2);
printf("%.2f is slope\n", m);
}