题解 | #取近似值#

取近似值

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

利用int取出整数部分,作差取出小数部分。与0.5作比较。对整数部分四舍五入

#include <iostream>
using namespace std;

int main() {
    float input = 0;
    cin >> input;

    int x = int(input);
    float y = input - x;
    if(y >= 0.5)
        cout << x+1 << endl;
    else
        cout << x << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

陈逸轩1205:才105 哥们在养生呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务