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:
Euclidian Distance:
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