URI Online Judge | 1015 Distance Between Two Points (Solution)

Problem Link:
https://www.urionlinejudge.com.br/judge/en/problems/view/1015

URI Online Judge | 1015

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>
#include<math.h>
  
int main()
{
    float x1,y1,x2,y2,p1,p2,res;
    scanf("%f %f %f %f", &x1, &y1, &x2, &y2);
    p1=x2-x1;
    p2=y2-y1;
    res=sqrt((p1*p1)+(p2*p2));
    printf("%.4f\n",res);
    return 0;
}

Comments

Popular posts from this blog

URI Online Judge | 1036 Bhaskara's Formula (Solution)

URI Online Judge | 1043 Triangle (Solution)

URI Online Judge | 1042 Simple Sort (Solution)