You are given two co-ordinates (x1, y1) and (x2, y2) of a two dimensional graph. Find the distance between them.
Input : x1, y1 = (3, 4) x2, y2 = (7, 7) Output : 5 Input : x1, y1 = (3, 4) x2, y2 = (4, 3) Output : 1.41421
We will use the distance formula derived from Pythagorean theorem. The formula for distance between two point (x1, y1) and (x2, y2) is
We can get above formula by simply applying Pythagoras theorem
Below is the implementation of above idea.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Program to calculate distance between two points in 3 D
- Program for distance between two points on earth
- Hammered distance between N points in a 2-D plane
- Distance between two points travelled by a boat
- Calculate speed, distance and time
- Find points at a given distance on a line of given slope
- Find the maximum possible distance from origin using given points
- Check whether it is possible to join two points given on circle such that distance between them is k
- Haversine formula to find distance between two points on a sphere
- Sort an Array of Points by their distance from a reference Point
- Distance between end points of Hour and minute hand at given time
- Find integral points with minimum distance from given set of integers using BFS
- Find the integer points (x, y) with Manhattan distance atleast N
- Program to calculate value of nCr
- Program to calculate age
- C program to calculate the value of nPr
- Efficient program to calculate e^x
- Write a program to calculate pow(x,n)
- Program to calculate the value of sin(x) and cos(x) using Expansion
- Program to calculate the value of nCr Efficiently
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t