问题描述:
求实数的绝对值。
输入:
输入数据有多组,每组占一行,每行包含一个实数。
输出:
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
样例输入:
123
-234.00
样例输出:
123.00
234.00
分析:
求取每个输入的数的绝对值,需要能够对数的正负进行判断,注意输出的格式要求
代码:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
double n;
while (cin >> n)
{
if (n >= 0)
printf("%.2lf\n", n);
else
printf("%.2lf\n", -n);
}
return 0;
}