求实数绝对值
Problem Description
求实数绝对值。
Input
输入数据有多组,每组占一行,每行包含一个实数。输入文件直到EOF为止!
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
Example Input
123
-234.00
Example Output
123.00
234.00
代码:
#include <stdio.h>
#include <math.h>
double f(double a);
int main()
{
double a;
while(scanf("%lf", &a) != EOF)
{
a = f(a);
printf("%.2lf\n", a);
}
return 0;
}
double f(double a)
{
if(a < 0)
{
a = -a;
}
return a;
}