C language implements rounding C language implements rounding

Directly upload the code

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

First define a constant a of floating point type and initialize it;

%lf is the input and output format character of floating point numbers, just like %d is the input and output format character of integer.

When outputting, %.0lf means outputting 0 digits after the decimal point, which here means rounding. If other questions require outputting two digits after the decimal point, it is %.2lf, and if it is three digits after the decimal point, it is %.3lf. And so on.

おすすめ

転載: blog.csdn.net/wangduduniubi/article/details/128523384