# C Program To Calculate Distance Between Two Points

This article is a tutorial which explains how to write a C program to calculate or find the distance between two points.

Formula to Calculate Distance Between Two Points:distance = √(a^{2}+ b^{2}) i.e. the distance between two points can be found out by calculating the square root of sum of squares ofand`a`

, Where`b`

= X`a`

_{2}-X_{1}and= Y`b`

_{2}- Y_{1}. (X_{1}, X_{2}) represent first point and (Y_{1}, Y_{2}) represent second point.

## C Program to Calculate the Distance Between Two Points

`/* Aim: Write a C program to calculate Distance Between Two Points */`

#include<stdio.h>
#include<math.h>
int main()
{
int x1,x2,y1,y2,a,b;
float distance;
printf("\n Enter co-ordinates of first point (x1,x2): ");
scanf("%d%d",&x1,&x2);
printf("\n Enter co-ordinates of second point (y1,y2): ");
scanf("%d%d",&y1,&y2);
a=x2-x1;
b=y2-y1;
distance = sqrt((a*a)+(b*b));
printf("\n The Distance Between Two Points is %f \n \n", distance);
return 0;
}

### Output:

Enter co-ordinates of first point (x1,x2): 4 6 Enter co-ordinates of second point (y1,y2): 8 -9 The Distance Between Two Points is 17.117243

### Explanation:

Accept the co-ordinate values of both points. Calculate**and**`a`

**according to the formula. Add**`b`

`a`

^{2}and`b`

^{2}then take the square root of result of this sum to calculate the distance between given two points. Display the distance.