VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-calculate-distance-two-points/

⇱ Program to calculate distance between two points - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to calculate distance between two points

Last Updated : 10 Feb, 2025

You are given two coordinates (x1, y1) and (x2, y2) of a two-dimensional graph. Find the distance between them.

Examples: 

Input : x1, y1 = (3, 4)
x2, y2 = (7, 7)
Output : 5

Input : x1, y1 = (3, 4)
x2, y2 = (4, 3)
Output : 1.41421

Calculate the distance between two points.

We will use the distance formula derived from Pythagorean theorem. The formula for distance between two point (x1, y1) and (x2, y2) is
Distance = 
We can get above formula by simply applying Pythagoras theorem

👁 calculate distance between two points
calculate distance between two points

Below is the implementation of above idea.


Output
1.41421
Comment