⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 计算欧几里德距离的c语言代码.txt

📁 c语言的一些常见的算法以及思考和改进的文章,写的很不错,花费了很大的精力从网络了搜罗的,希望大家喜欢.
💻 TXT
字号:
计算欧几里德距离的C语言代码[原创] 
设xn和yn分别是n维度量空间中的点,则其欧几里德距离定义为:

d(x,y)=(∑(xi-yi)2)1/2

当n=2时,则为平面上两点的距离,当n=3时,则为三维空间中两点的距离。

#i nclude <math.h>

double fun(double p[],double q[],int n)
{
   int i;
   double result=0.0;
   for(i=0;i<n;i++)
      result+=(p[i]-q[i])*(p[i]-q[i]);
   return sqrt(result);
}

void output(double array[],int n)
{
   int i;
   for(i=0;i<n;i++)
      printf("%14lf",array[i]);
}

void main()
{
   double x[5]={1.2,1.5,3.4,5.8,7.0};
   double y[5]={3.1,4.2,5.3,6.4,8.9};
   double result;
   result=fun(x,y,5);
   printf("\nThe first point is:\n");
   output(x,5);
   printf("\nThe second point is:\n");
   output(y,5);
   printf("\nThe distance is:%14lf\n",result);
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -