Pages

This blog is under construction

Thursday, December 20, 2018

C program to compute distance between two points (x1,y1) and (x2,y2).

Distance between two points (x1,y1) and (x2,y2) is governed by the formula


D2 = (x2 -x1 )2 +(y2 -y1)2


#include<stdio.h>
#include<math.h>
void main()
{
int x1,x2,y1,y2;
float D;
D=0;
x1=20;
x2=30;
y1=40;
y2=50;
D=sqrt((x2-x1)*(x2-x1)+ (y2-y1)* (y2-y1));
printf("Distance between to points is= %f",D);
}

Distance between to points is= 14.142136

No comments:

Post a Comment