fabvy12 发表于 2019-10-17 01:29:09

新生小白求助。一道函数题

#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);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

fabvy12 发表于 2019-10-17 09:03:34

已解决,
页: [1]
查看完整版本: 新生小白求助。一道函数题