Distance Between 2 Places

Premium Content - Free Preview

You're creating travel software, and need to calculate the distance between 2 locations located at (x1, y1) and (x2, y2) on a 2D grid. You will be given a list of doubles as input in the following order: x1, y1, x2, y2. Calculate and print the distance between the cities, rounded to 3 decimal places.

End of Free Content Preview. Please Sign in or Sign up to buy premium content.


  • Isnt there an esier way to round up numbers to n decimal places?

    a solution:
    my code

  • We have to make a precision, for which there is no method? That's brutal.

  • I finally got the precision done, but only by copying and pasting a solution for that issue from Quora. It really would be helpful if we were led to a solution, sometimes. Right now I don't feel I'm learning from this.

  • In this case, Googling for how to round numbers would be good practice for real world programming.

Contact Us
Sign in or email us at [email protected]