Link Search Menu Expand Document

Challenge - Calculate Distance Between Two Points

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: √​(x1−x2)​2​​+(y1−y2)​2​​​​​

  • Return the value of distance


Two instances of point

Output The output of the code should be:

  The distance between x and y

Coding Exercise

struct Point {
	x: i32,
	y: i32
fn test(_point1: Point, _point2: Point)-> f32 {
	// Write code here!

Good luck! 🤞