Challenge: Calculate Distance Between Two Points

This challenge will test your knowledge of structs.

We'll cover the following

Problem Statement

  • A struct Point is given which has two items, x and y.

  • The function test is given which has two instances of points initialized with some value of x and y.

  • The task is to calculate the distance between the two points.

    The distance between two points is: (x1x2)2+(y1y2)2\sqrt{(x1 - x2)^2+(y1 - y2)^2}

  • Return the value of distance

Input

  Two instances of point

Output

The output of the code should be:

  The distance between x and y

Coding Exercise

Write your code below. It is recommended​ that you try solving the exercise yourself before viewing the solution.

Note: There is a test function given in the code for testing purposes. Do not modify it.

Good luck! 🤞

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy