Problem Description
Enter the coordinates of 2 points in the plane coordinate system to output the distance between them
Input
Enter 4 floating-point numbers x1 y1 x2 y2, respectively (x1,y1) (x2,y2) coordinates (multiple sets of data)
Output
Outputs the distance between them, preserving 2 decimal places (one row per group of data)
Sample Input
1 0 2 0
Sample Output
1.00
1#include <stdio.h>2 3#include <math.h>4 5 6 7 intMain ()8 9 {Ten One floatX1,y1,x2,y2; A - DoubleLen; - the while(SCANF ("%f%f%f%f", &x1,&y1,&x2,&y2)! =EOF) - - { - +Len=sqrt ((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1)); - +printf"%.2lf\n", Len); A at } - - return 0; - -}
Other code:
1#include <stdio.h>2#include <math.h>3 intMain ()4 {5 DoubleX1,x2,y1,y2;6 Doubledistance;7 while(SCANF ("%LF%LF%LF%LF", &x1,&y1,&x2,&y2)! =EOF)8 {9Distance=sqrt (Fabs (x1-x2) *fabs (x1-x2) +fabs (y1-y2) *fabs (y1-y2));Tenprintf"%.2lf\n", distance); One } A return 0; -}
Wuhan University of Science and Technology acm:1006:0 starting point algorithm 25--to find the distance between two points