题解 | #取近似值#
取近似值
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")