为什么宏改成#define PRINTF "%.3lf %.3lf"就错了呢

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

linyiyi123456 @ 2023-03-08 14:43:30

#include<stdio.h>
#include<math.h>
#define PRINTF "%lf %lf"
double C(double x1,double x2,double y1,double y2)
{
    double sum;
    sum=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
    return sum;
}
int main()
{
    double x1,x2,x3,y1,y2,y3,sum,c1,c2,c3;
    scanf(PRINTF,&x1,&y1);
    scanf(PRINTF,&x2,&y2);
    scanf(PRINTF,&x3,&y3);
    c1=C(x1,x2,y1,y2);
    c2=C(x2,x3,y2,y3);
    c3=C(x3,x1,y3,y1);
    sum=c1+c2+c3;
    printf("%.2lf",sum);
    return 0;
}

by CreutzWilknare @ 2023-03-08 14:46:30

scanf里放%.3lf,给我看木了


by Milthm @ 2023-03-08 15:47:15

@linyiyi123456 scanf或许不是这样用的……


by mashduihca @ 2023-03-08 16:20:48

先不说.3lf,就你一句scanf(PRINTF)就把我看麻了。


by linyiyi123456 @ 2023-03-08 18:10:37

@songjiahao_ 不能这样用么,妈呀,好丢脸,谢谢


by Milthm @ 2023-03-08 18:35:05

@linyiyi123456 等等等等,我或许看错了,这个代码应该是对的啊(?,提交上去可以AC的


by linyiyi123456 @ 2023-03-08 23:23:33

@songjiahao_ 把.3去掉的话是对的,我之前不晓得为什么不可以加.3


by Milthm @ 2023-03-09 18:22:31

@linyiyi123456 scanf里面加类型就可以了,不用加限制


by linyiyi123456 @ 2023-03-09 23:21:00

@songjiahao_ 好的我知道了,谢谢你


|