Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Manhattan Distance (M.D.) between two points A(x1, y1) and B(x2, y2) is defined as follows: M.D. = |x1 - x2| + |y1 - y2| Write


Manhattan Distance (M.D.) between two points A(x1, y1) and B(x2, y2) is defined as follows:

M.D. = |x1 - x2| + |y1 - y2|

image

Write down a structure that will model a point in 2-dimensional space. Using the above structure take input of two locations and calculate Manhattan distance between them.

Input Format

The input contains four floating point values in the following format:

x1 y1

x2 y2

Constraints


Output Format

Print a single floating point number, with two places after the decimal point, denoting the Manhattan Distance between (x1, y1) and (x2, y2) as shown in the sample output.

Sample Input 0

5 41 1

Sample Output 0

Manhattan Distance = 7.00

Explanation 0

x1 = 5, y1 = 4 x2 = 1, y2 = 1     |x1 - x2| + |y1 - y2|     = |5-1| + |4-1|    = |4| + |3|    = 4 + 3    = 7.00

Sample Input 1

-100 9.87100 0.12

Sample Output 1

Manhattan Distance = 209.75

Manhattan Distance = 10 Pyt hagor ean Distance = V50 = 7.07 %3D

Step by Step Solution

3.47 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

Here is the required code implemented in C having Complete Working Code Sample inputs and outputs Step by step explanations of working of Code Along w... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Operations Research An Introduction

Authors: Hamdy A. Taha

9th Edition

013255593X, 978-0132555937

More Books

Students also viewed these Programming questions