To find the distance between two points in rust, we can use the Euclidean distance formula. Here's an example implementation:
main.rs370 chars16 lines
In this example, we define a function euclidean_distance
that takes four parameters: the x and y coordinates of the two points we want to find the distance between. The function calculates the distance using the Euclidean distance formula sqrt((x2 - x1)^2 + (y2 - y1)^2)
.
In main()
, we define the coordinates of the two points and print out the distance between them. Running this code will output:
main.rs46 chars2 lines
gistlibby LogSnag