Distance between two coordinate points coderinme

Distance between two coordinate points coderinme

Distance between two coordinate points coderinme
The distance formula is derived from the Pythagorean theorem. To find the distance between two points (x1,y1) and (x2,y2), all that you need to do is use the coordinates of these ordered pairs and apply the formula
Given two points P1 (x1,y1) and P2(x2,y2) on a Cartesian plane, distance between them is calculated using the formula:
D = sqrt((x1-x2)2+(y1-y2)2)
Now let’s code it in C

#include<stdio.h>
int main()
{
float x1,x2,y1,y2,Dist;
printf("Enter the value of x1: ");
scanf("%f",x1);
printf("Enter the value of y1: ");
scanf("%f",&y1);
printf("Enter the value of x2: ");
scanf("%f",&x2);
printf("Enter the value of y2: ");
scanf("%f",&y2);
Dist=sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) );
printf("The distance between the points (%.2f,%.2f) and (%.2f,%.2f): %.2f",x1,y1,x2,y2,Dist);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Distance between two coordinate points coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.