求两点之间最短距离的C语言源代码

来源:百度知道 编辑:UC知道 时间:2024/06/13 15:43:04

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
printf("输入两点坐标:\n");
double x1,y1,x2,y2,length;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
length = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
printf("%lf\n",length);
system("pause");
return 0;
}

只给你写代码了

int minA;//最短的距离变量
int maxA;//其他的变量
if(minA<maxA)
{
printf("%d",minA);
}
else
minA=maxA;
printf("%d",maxA);

#include <stdio>
#include <math.h>
int main(void)
{float a[2],b[2],d;
scanf("%f %f",&a[0],&a[1]);
scanf("%f %f",&b[0],&b[2]);
d=sqrt((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1]));
printf("Answer is %f.2\n",d);
putchar();
return 0;
}