题解 | #取近似值#

取近似值

https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a

#include <stdio.h>

int main() {
    float x;
    scanf("%f",&x);
    float temp=0.0;
    for(float i=1.0;i<x;i++)
        temp+=1.0;
    x=x-temp;
    if(x>=0.5)
       printf("%d",(int)(temp+1));//类型转换
    else
       printf("%d",(int)(temp));
}

全部评论

相关推荐

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