• abs()函数和fabs()函数
    头文件为cmath,分别用于整数和浮点数的取绝对值
#include <iostream>//输入输出
#include <cmath>
using namespace std;

const int N = 100010;

void main() {
	int a;
	float b;
	cin >> a >> b;
	a = abs(a);
	b = fabs(b);
	cout << a << endl << b << endl;
}

举个栗子:
input:-4 -2.5
output:4 2.5


版权声明:本文为qq_16488989原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_16488989/article/details/120148836