[编程题]取近似值
来源:互联网 发布:cocos2d js下载 编辑:程序博客网 时间:2024/05/21 15:49
Talk is cheap, show me the code.
一、问题描述
写出一个程序,接受一个正浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整。
输入描述:
输入一个正浮点数值
输出描述:
输出该数值的近似整数值
输入例子:
5.5
输出例子:
6
二、问题分析
这道题比较简单,但是实现方式也有多种,比如用到cmatch头文件和不用就有两种方式。
解题方式1:
#include <iostream>#include <cmath>using namespace std;int main(){ float f; while (cin >> f) { cout << round(f) << endl; } return 0;}
解题方式2:
#include <iostream>using namespace std;int main(){ float f; while (cin >> f) { cout << static_cast<int>(f + 0.5) << endl; } return 0;}
0 0
- [编程题]取近似值
- 算法题:取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 取近似值
- 【华为OJ】取近似值
- Eclipse添加dtd文档为xml编辑提供代码提示功能
- js闭包总结
- JAVA用swing做个日历
- 识别macho block的ida脚本
- nuoj 114 大数
- [编程题]取近似值
- 2016/12/8 1002.Babelfish
- DOS批处理前言
- mybatis多表关联查询
- Android 6.0下出错: UnsatisfiedLinkError: dlopen failed . text relocations
- hdu 5988 费用流
- 我在路上---贪懒
- CVPR 2016-12-01
- 2016/12/8 1003. 简单哈希