Two-Point distance

Source: Internet
Author: User
Two-Point distance

Description

Enter two coordinates (x1, Y1), (X2, Y2) (0 <= x1, x2, Y1, Y2 <= 1000), and calculate and output the distance between two points.
Input
Enter an integer N (0 <n <= 1000) in the first row, indicating that there are N groups of test data. Then each group occupies one row and consists of four real numbers, representing X1, respectively, y1, X2, Y2, and data are separated by spaces.
Output
For each group of input data, a row is output, and the result is retained with two decimal places.
Sample Input
20 0 0 10 1 1 0
Sample output
1.001.41

 #include <stdio.h>#include <math.h>int main(){    int n;    double sum;scanf("%d",&n);double x1,x2,y1,y2;while(n--){    sum = 0;    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);    sum = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));    printf("%.2f",sum);    printf("\n");}return 0;}        

 

Two-Point distance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.