快乐地WA声,响了五声

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

AC__king @ 2022-10-09 10:30:38

谁知道printf("%.2lf\n",q);他只输出0.00,用cout还好

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d,e,f,q,w,o;
    cin>>a>>b>>c>>d>>e>>f;
    q=sqrt((a-c)*(a-c)+(b-d)*(b-d));
    w=sqrt((a-e)*(a-e)+(b-f)*(b-f));
    o=sqrt((c-e)*(c-e)+(d-f)*(d-f));
    q=q+w+o;
    printf("%.2lf\n",q);
    return 0;
}

by Tibrella @ 2022-10-09 10:37:43

你q声明的是int咋用lf输出


by Sir_en @ 2022-10-09 10:48:58

正确的)


by zz_z2Spider @ 2022-10-09 11:01:05

@AC__king int该用的是%d,兄弟。


by 2019jd12 @ 2022-10-09 11:26:52

正解


by 孙轩宇 @ 2022-10-18 15:00:20

int和double的表示方法不一样,应该强制转成double或

printf("%d.00",q);

by As_Nerve @ 2022-10-19 08:16:12

q定义成double类型


by AC__king @ 2023-02-24 19:07:36

彳亍,时隔多年我又双叕回来了.......

啊.......

原来这错误其实很好找,谢谢大佬


|