B - Calculation of distance between two points
Two input coordinates (X1, Y1), (X2, Y2), and calculates the distance between the two outputs.
Input
A plurality of input data sets, each representing a line of four real numbers, respectively, separated by a space between the x1, y1, x2, y2, data.
Output
For each case, an output line, the results of two decimals.
Sample Input
0 0 0 1 0 1 1 0
Sample Output
1.00 1.41
Code Example:
#include<stdio.h>
#include<math.h>
int main()
{
float x1,y1,x2,y2;
while(scanf("%f %f %f %f",&x1,&y1,&x2,&y2)!=EOF){
printf("%.2f\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
}
Treatment on multiple sets of data may also be as follows:
#include<stdio.h>
#include<math.h>
int main()
{
float x1,y1,x2,y2;
while(~scanf("%f %f %f %f",&x1,&y1,&x2,&y2))
{
printf("%.2f\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
}
NAND operation: ~
1 Take 0,0 take a
~ 1 = 0~0 = 1