Write a program that prompts the user to enter the coordinates (x, y) of two points and then calculates the straight line distance between them. The required formula is

Solution

To simplify things, the terms  (x1 – x2)2 and  (y1 – y2)2  are calculated individually and the results are assigned to two temporary variables.

PHP

Java

C++

C#

Visual Basic

Python

or you can do it more quickly as shown here

PHP

Java

C++

C#

Visual Basic

Python

Leave a Reply

Your email address will not be published. Required fields are marked *

This article is taken from a book of mine. If you enjoyed it, please visit my author's page inand check out all of my books!