📅  最后修改于: 2020-09-26 15:52:06             🧑  作者: Mango
可以将labs() 函数视为abs()的long int
版本。
它在
[Mathematics] |x| = labs(x) [C++ Programming]
long labs(long x);
long int labs(long int x);
labs() 函数采用long
或long int
类型的单个参数,并返回相同类型的值。
x
:返回绝对值的long或long int数据。
labs() 函数返回x的绝对值,即| x |。
#include
#include
using namespace std;
int main()
{
long int x,y;
x = -9999999L;
y = 10000000L;
cout << "labs(" << x << ") = |" << x << "| = " << labs(x) << endl;
cout << "labs(" << y << ") = |" << y << "| = " << labs(y) << endl;
return 0;
}
运行该程序时,输出为:
labs(-9999999) = |-9999999| = 9999999
labs(10000000) = |10000000| = 10000000