【C】保留几位有效数字

使用%.6g!!

例子

#include<stdio.h>
double getBMI(float m,float h){
    return (m/(h*h));
}
int main(){
    double m,h;
    scanf("%lf %lf",&m,&h);
    float BMI=getBMI(m,h);
    if (BMI<18.5){
        printf("Underweight");
    }
    else if (BMI>=18.5&&BMI<=24){
        printf("Normal");
    }
    else{
        printf("%.6g\nOverweight",BMI);
    }
    
    return 0;
}

链接:https://www.luogu.com.cn/problem/P5714

© 版权声明
THE END
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容