Calculate Distance Between Two Points C Program

C Program To Calculate Distance Between Two Points

Here’s a Code to Calculate Distance between Two Points in C Programming Language. This C Code to Find Distance between Two Points on a Plane is a very simple one and only requires calculation using a Formula.

Every Point on a Graph has Two Coordinates. In this C Program for Calculation of Distance of Two Points, we make use of the same formula. Let us assume that the Two Points are M and N. Therefore, M and N will have Two Coordinates each both representing M – Axis Coordinate and N – Axis Coordinate.

Therefore, M = ( X1, Y1) and N = (X2, Y2)

The Distance Formula between Two Points is derived from the Pythagoras Theorem. According to the Pythagoras Theorem,

(Hypotenuse)2 = (Base)2 + (Height)2

Example: z2 = x2 + y2

Formula To Calculate Distance Between Two Points in C Programming

Distance Between Two Points =  √ (x1 – y1)2 + (x2 – y2)2

Also Read: Calculate Roots of a Quadratic Equation in C Programming

Command: gcc test.c -lm

Output

If you find any doubts or compilation errors in this C Program To Calculate Distance Between Two Points, let us know about it in the comment section.

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

3 thoughts on “Calculate Distance Between Two Points C Program”

• June 2, 2016 at 8:36 pm

I see that this Distance Calculation between Two Points is compiled in Ubuntu. Do we have to use the -lm parameter if we compile this program in Windows. I am using Codeblocks Editor.