[URI Online Judge] – 1015 – Distance Between Two Points

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 Input Sample 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 <cstdio>
#include <cmath>
int main(){
 float x1, y1, x2, y2;
 scanf("%f %f", &x1, &y1);
 scanf("%f %f", &x2, &y2);
 printf("%.4f\n", std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
}
Advertisements

3 thoughts on “[URI Online Judge] – 1015 – Distance Between Two Points

  1. Hey, how r y doing?
    what is wrong if i do this?

    #include <stdio.h>
    #include <math.h>
    int main() {

    float x1, y1, x2, y2, x, p1, p2;

    scanf(“%f %f”, &x1, &y1);
    scanf(“%f %f”, &x2, &y2);

    x = sqrt((x2 – x1) * (x2 – x1) + (y2 – y1) * (y2 – y1))

    printf(“%.4f\n”, x);

    Like

  2. Like, when i do in a C program I got a correct program, but when I paste on URI i have a
    Compilation error, its saying that I did wrong the last line.. pls help senpai ;-;

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s