Answer:
Check the explanation
Explanation:
Points to consider:
We need to take the input from the user
We need to find the manhatan distance and euclidian using the formula
(x1, y1) and (x2, y2) are the two points
Manhattan:
![|x_1 - x_2| + |y_1 - y_2|](https://tex.z-dn.net/?f=%7Cx_1%20-%20x_2%7C%20%2B%20%7Cy_1%20-%20y_2%7C)
Euclidian Distance:
![\sqrt{(x1 - yl)^2 + (x2 - y2)^2)}](https://tex.z-dn.net/?f=%5Csqrt%7B%28x1%20-%20yl%29%5E2%20%2B%20%28x2%20-%20y2%29%5E2%29%7D)
Code
#include<stdio.h>
#include<math.h>
struct Point{
int x, y;
};
int manhattan(Point A, Point B){
return abs(A.x - B.x) + abs(A.y- B.y);
}
float euclidean(Point A, Point B){
return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2));
}
int main(){
struct Point A, B;
printf("Enter x and Y for first point: ");
int x, y;
scanf("%d%d", &x, &y);
A.x = x;
A.y = y;
printf("Enter x and Y for second point: ");
scanf("%d%d", &x, &y);
B.x = x;
B.y = y;
printf("Manhattan Distance: %d\n", manhattan(A, B));
printf("Euclidian Distance: %f\n", euclidean(A, B));
}
Sample output