HJ7 取近似值 | 杂乱无章的初级程序员的题解

取近似值

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

"IEEE 754 round-to-nearest-even",需要手动对小数部分进行判断

#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
    float f;
    cin >> f;

    float intpart, fractpart;
    fractpart = modff(f, &intpart);
    cout << fixed << setprecision(0) << ((fractpart >= 0.5f) ? (intpart + 1.0f) : intpart) << endl;
}
#华为机试#
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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