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
andy
. -
The function
test
is given which has two instances of points initialized with some value ofx
andy
. -
The task is to calculate the distance between the two points.
The distance between two points is:
-
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