为何满江红

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

Lydia_qwq @ 2021-09-15 22:09:21

Code:

#include<iostream>
#include<cmath>
using namespace std;
double dis(double x,double _x,double y,double _y)
{
    return sqrt(((_x-x)*(_x-x))+(_y-y)*(_y-y));
}
int main()
{
    int x1,x2,y1,y2,z1,z2,ans;
    ans=dis(x1,x2,y1,y2)+dis(x1,x2,z1,z2)+dis(y1,y2,z1,z2);
    printf("%.2f",ans);
    return 0;
}

by OnlyExtreme @ 2021-09-15 22:12:13

@蝴蝶小队队长2 输入呢?


by thomas_zjll @ 2021-09-15 22:12:23

int存不了小数的,把ans拿出来单独命名一个double ans


by dn0pf902 @ 2021-09-15 22:12:41

@蝴蝶小队队长2 没有输入


by Need_No_Name @ 2021-09-15 22:25:35

@蝴蝶小队队长2 输入啊大哥,还有,你的ans是int类型的


|