求助

B2016 浮点数向零舍入

great_mad @ 2023-10-22 22:19:48

#include <stdio.h>
int main()
{
    double x;
    scanf("%lf",&x);
    if(x>0)
    printf("%ld",(long long)x);
    if(x<0) 
    printf("%ld",(long long)(x-1));
    return 0;
}

by 2huk @ 2023-10-22 22:20:32

有没有一种可能,可以直接:

#include<iostream>
using namespace std;
int main(){
    double a;
    cin>>a;
    cout<<(long long)a;
    return 0;
}

by 2huk @ 2023-10-22 22:21:11

求关注


by great_mad @ 2023-10-22 22:32:36

@2huk 这是什么语言,我看不懂


by 2huk @ 2023-10-22 22:35:05

像这样:

#include<cstdio>
using namespace std;
int main(){
    double a;
  scanf("%lf",&a);
  printf("%lld",(long long)a);
    return 0;
}

by Argvchs @ 2023-10-22 22:42:21

@great_mad cpp


by great_mad @ 2023-10-23 08:29:20

@2huk 为什么要用long long


by linjianju_xi @ 2023-10-28 15:27:55

@great_mad 防止数据太大


|