|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#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;
}
double dist( double x1, double y1, double x2, double y2 )
{
double result;
double a,b;
a=pow((x1-x2),2);
b=pow((y1-y2),2);
result=sqrt((a+b));
return result;
} //这是我的代码。在编译器上答案是对的,但是在PTA上答案显示编译错误
本题要求实现一个函数,对给定平面任意两点坐标 //这是题目。
​求这两点之间的距离。
函数接口定义:
double dist( double x1, double y1, double x2, double y2 );
其中用户传入的参数为平面上两个点的坐标(x1, y1)和(x2, y2),函数dist应返回两点间的距离。
编译错误,内容是这个
.c:21:5: error: redefinition of ‘main’
int main()
^~~~
a.c:6:5: note: previous definition of ‘main’ was here
int main()
^~~~
a.c: In function ‘main’:
a.c:10:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.c: In function ‘main’:
a.c:25:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|