C语言求助 80分代码 #5错了

P5735 【深基7.例1】距离函数

wupeihao @ 2020-12-10 19:40:30

# include "stdio.h"
# include "math.h"
float length(int a,int b,int c,int d);
int main(void)
{
    int a[3][2],i;
    float perimeter=0,l1,l2,l3;
    for(i=0;i<3;i++)//输入三边坐标 
    {
        scanf("%d%d",&a[i][0],&a[i][1]);
    }
    l1=length(a[0][0],a[0][1],a[1][0],a[1][1]);
    l2=length(a[1][0],a[1][1],a[2][0],a[2][1]);
    l3=length(a[0][0],a[0][1],a[2][0],a[2][1]);
    perimeter=l1+l2+l3;
    printf("%.2f",perimeter);
} 
float length(int a,int b,int c,int d)
{
    float z;
    z=sqrt((a-c)*(a-c)+(b-d)*(b-d));
    return (z);
}

第五个错了,求教


by dayux @ 2020-12-10 19:42:34

建议用double试一下


by wupeihao @ 2020-12-10 19:48:02

@dayux 用了double还是错的...


by dayux @ 2020-12-10 19:51:50

输入数据的时候也要double


by wupeihao @ 2020-12-10 20:00:09

@dayux 输出也改了...


by LaWekokomidy @ 2020-12-10 20:13:41

读入的坐标中可能会有小数,数组a的类型改下试试?


by wupeihao @ 2020-12-10 20:22:16

@N夏之哀伤N 通过了,谢谢


|