[英]Calculate distance between 2 coordinates with function in c programing (x,y,z)
[英]Declare and define the function distance() to find the Euclidean distance between the two points (x[0], y[0]) and (x[1], y[1]) in c
声明并定义函数distance(),以找到两个点(x [0],y [0])和(x [1]之间的√((x1-x2)²+(y1-y2)²) ],y [1])此函数应只计算并返回答案。
C程序-----
双倍距离(double x [],double y []);
我还应该放些什么。 我要在此函数中包括距离吗?还是要创建一个新的距离?
double distance(double x[], double y[]);
是函数声明。
double distance(double x[], double y[]) {
//Write code here that returns a double
}
是函数定义。
问题似乎希望您同时执行。
这是最简单的distance()函数定义:
`double distance(double x, double y){
return 1/sqrt(((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1])));
}`
请注意,如果使用它来比较距离,则使用距离的平方最快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.