1. 程式人生 > >求絕對值(分支結構)

求絕對值(分支結構)

Description
求實數的絕對值。本題用於練習選擇結構(或稱分支結構)。正數的絕對值是其本身,負數的絕對值是其相反數。

Input
有多個測試資料,一個佔一行,每行是一個實數 a 。

Output
為每個測試資料輸出一行:a的絕對值,結果保留兩位小數。

Sample Input
-126.369
66
-10
0

Sample Output
126.37
66.00
10.00
0.00

#include <stdio.h>
#include <math.h>
int main(void)
 {   float a;
     while (scanf
("%f",&a)!=EOF) { printf("%.2f\n",fabs(a)); } return 0; }