安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

【例422】 数学课上在一节生动有趣的数学课上老师问同学们:给出一个浮点数怎么判断这个数离前后相邻两个整数哪个更近则输出距离更近的整数。请你按照四舍五入原则编程输出这个数。【输入】输入一行包含 1 个数:n00≤n≤1000000表示题目要求输入的浮点数。题目保证输入浮点数小数点后保留最多8位。【输出】输出共计一行包含一个数表示题目所求的距离更近的整数请用c++代码写出要用上rand

  • 日期: 2027-08-31
  • 标签: 社会

#include #include

int main() { double n; std::cin >> n;

int num1 = std::floor(n);
int num2 = std::ceil(n);

if (n - num1 < num2 - n) {
    std::cout << num1 << std::endl;
} else {
    std::cout << num2 << std::endl;
}

return 0;

}

【例422】 数学课上在一节生动有趣的数学课上老师问同学们:给出一个浮点数怎么判断这个数离前后相邻两个整数哪个更近则输出距离更近的整数。请你按照四舍五入原则编程输出这个数。【输入】输入一行包含 1 个数:n00≤n≤1000000表示题目要求输入的浮点数。题目保证输入浮点数小数点后保留最多8位。【输出】输出共计一行包含一个数表示题目所求的距离更近的整数请用c++代码写出要用上rand

原文地址: https://www.cveoy.top/t/topic/iifm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: import stuManage from componentstuManage; 正确的引入方法
  • 下一篇: 请把以下这段内容精简:A lawn mower reel is the part of a lawn mower that cuts and trims the grass on your lawn It usually consists of a rotating blade that can be powered by an electric or gasoline engine The re

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2