输入:-7
输出:7
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cout << "输入一个有理数:";
cin >> x;
int res = 0;
res = abs(x);
cout << "它的绝对值是:" << res << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cout << "输入一个有理数:";
cin >> x;
int res = 0;
res = abs(x);
cout << "它的绝对值是:" << res << endl;
return 0;
}