View Problem

Find the distance between two points

DiskEdit
csharp
System.Drawing.Point p = new System.Drawing.Point(13, 14),
p1 = new System.Drawing.Point(10, 10);
double distance = Math.Sqrt(Math.Pow(p1.X - p.X, 2) + Math.Pow(p1.Y - p.Y, 2)));
ExpandDiskEdit
erlang
Distance = distance({point, 34, 78}, {point, 67, -45}),
io:format("~.2f~n", [Distance]).
ExpandDiskEdit
erlang
Distance = distance(point:new(34, 78), point:new(67, -45)),
io:format("~.2f~n", [Distance]).
ExpandDiskEdit
cpp C++/CLI .NET 2.0
Point p1 = {34, 78}, p2 = {67, -45};
double distance = ::distance(p1, p2);
Console::WriteLine("{0,3:F2}", distance);
ExpandDiskEdit
fsharp
let distance' = distance (34, 78) (67, -45)
printfn "%3.2f" distance'
ExpandDiskEdit
groovy
distance = distance(x1, y1, x2, y2)
ExpandDiskEdit
groovy
distance = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
ExpandDiskEdit
go
import "fmt"
import "math"

type Point struct {
x, y float64
}

func (p Point) distance(other Point) (float64) {
dx := p.x - other.x
dy := p.y - other.y
return math.Sqrt(dx * dx + dy * dy)
}

func main() {
origin := Point{ 0, 0 }
point := Point{ 1, 1 }

fmt.Println(point.distance(origin))
}

Submit a new solution for csharp, erlang, cpp, fsharp ...
There are 18 other solutions in additional languages (clojure, fantom, haskell, java ...)