Wednesday, December 2, 2015

Uri problem 1015 solve

Problem :

Distance Between Two Points

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read the four values corresponding to the x and y axes of two points in the plane, p1 (x1, y1) and p2 (x2, y2) and calculate the distance between them, rounded to four decimal places, according to the formula:
Distance = 

Input

The input file contains two lines with data. The first one contains two double numbers with one digit after the decimal point, respectly: x1 y1 and the second one also contains two double numbers with one digit after the decimal point: x2 y2.

Output

Calculate and print the distance, using the above phormula, with 4 digits after the decimal point.
Sample InputSample Output
1.0 7.0
5.0 9.0
4.4721
-2.5 0.4
12.1 7.3
16.1484
2.5 -0.4
-12.2 7.0
16.4575

Solution:

#include <stdio.h>
  
int main() {
  
    float x1,y1,x2,y2,first,sec,sum;
 
    scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
 
    first=x2-x1;
 
    sec=y2-y1;
 
    sum=sqrt((first*first)+(sec*sec));
 
    printf("%.4f\n",sum);
 
 
  
    return 0;
}

No comments:

Post a Comment