21986 牛牛学说话之-浮点数

牛牛学说话之-浮点数

https://ac.nowcoder.com/acm/problem/21986

#include<stdio.h>
int main ()
{
    float a;
    scanf("%f",&a);
    printf("%.3f",a);
    return 0;
}

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

未通过
cout相当于%g
%g根据数值的大小自动选%f格式或%e格式中输出时占宽度较小的一种,且不输出无意义的0,即%g根据结果自动选择科学记数法或小数。


#include<stdio.h>
int main ()
{
    double a;
    scanf("%lf",&a);
    printf("%.3f",a);//或%.3lf
    return 0;
}

warning: format '%f' expects argument of type 'float', but argument 2 has type 'double' [-Wformat=]
格式控制符: double -> %lf float -> %f

全部评论

相关推荐

4 收藏 评论
分享
牛客网
牛客企业服务