鱼C论坛

 找回密码
 立即注册
查看: 2328|回复: 1

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

[复制链接]
发表于 2019-10-17 01:29:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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上答案显示编译错误

本题要求实现一个函数,对给定平面任意两点坐标    //这是题目。
&#8203;求这两点之间的距离。
函数接口定义:
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);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-10-17 09:03:34 | 显示全部楼层
已解决,
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-4 15:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表