经典算法——求绝对值溢出问题
2016-03-29 12:52
441 查看
Problem Description
求实数的绝对值。
Input
输入数据有多组,每组占一行,每行包含一个实数。
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
Sample Input
Sample Output
将x,res由float类型改为double类型就行:
求实数的绝对值。
Input
输入数据有多组,每组占一行,每行包含一个实数。
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
Sample Input
123 -234.00
Sample Output
123.00 234.00
#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { float x; float res; while (cin >> x) { res = x>=0 ? x : -1 * x; printf("%.2f\n",res); } return 0; }
将x,res由float类型改为double类型就行:
#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { double x; double res; while (cin >> x) { res = x>=0 ? x : -1 * x; printf("%.2f\n",res); } return 0; }
相关文章推荐
- CreateCompatibleDC 和 CreateCompatibleBitmap
- iOS开发者程序许可协议之简单介绍
- java接口可以实例化吗?
- 拖延症
- HDU--1166敌兵布阵(线段树)
- HDC,CDC,CClientDC的区别和联系是什么?
- 比较两个mysql数据库表结构的差异
- 索引的原理
- ceph 存储系统
- Nginx+Tomcat+Memcached 集群
- 自定义UICollectionViewFlowLayout
- ios:画直线和虚线
- Intellij IDEA 的使用
- 百度地图开发(一)——地图定位
- 网上出现的js小数计算的除法优化
- css3
- ubuntu下搭建erlang编程环境
- swift-UITabBarController 设置选中和未选中状态文字图片颜色或使用原图
- 机器学习基础(三十) —— 线性回归、正则化(regularized)线性回归、局部加权线性回归(LWLR)
- leetcode 每日一题 257. Binary Tree Paths