标签:ams str cti main mat tom ase htm cal
本题要求实现一个函数,对给定平面任意两点坐标(x?1??,y?1??)和(x?2??,y?2??),求这两点之间的距离。
double dist( double x1, double y1, double x2, double y2 );
其中用户传入的参数为平面上两个点的坐标(x1
, y1
)和(x2
, y2
),函数dist
应返回两点间的距离。
#include <stdio.h>
#include <math.h>
double dist( double x1, double y1, double x2, double y2 );
int main()
{
double x1, y1, x2, y2;
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
printf("dist = %.2f\n", dist(x1, y1, x2, y2));
return 0;
}
/* 你的代码将被嵌在这里 */
10 10 200 100
dist = 210.24
1 double dist(double x1,double y1,double x2,double y2){ 2 double area=0; 3 double a=0,b=0; 4 double c=0; 5 a=fabs(x1-x2); 6 b=fabs(y1-y2); 7 c=a*a+b*b; 8 if(c!=0){ 9 area=sqrt(c); 10 return area; 11 } 12 else 13 return 0; 14 }
标签:ams str cti main mat tom ase htm cal
原文地址:https://www.cnblogs.com/samgue/p/13187591.html