#include <iostream>
using namespace std;
#include <cmath>
int main() {
double x;
while (cin >> x) {
x = fabs(x); (直接将x的绝对值赋值给x并打印出来)
printf("%.2lf\n", x);
}
return 0;
}
这是用了函数的做法更为方便
#include <iostream>
using namespace std;
#include <cmath>
int main() {
double x;
while (cin >> x) {
x = fabs(x); (直接将x的绝对值赋值给x并打印出来)
printf("%.2lf\n", x);
}
return 0;
}
这是用了函数的做法更为方便